There's no law against him saying the paper should name the source, nor is there any law against directly asking the paper to name its source. The president was at a campaign rally, and his speech is protected by the same First Amendment that protects the New York Times.
At the federal level, the paper could be forced to reveal the source, but it would have to obtain a subpoena and probably spend quite a bit of time litigating over whether that subpoena was legitimate.
Although the law does not require it, Department of Justice guidelines restrict prosecutors' ability to obtain this information. They're fairly detailed, but the most relevant part is here:
Members of the Department must consult with the Criminal Division before taking steps to enforce subpoenas issued to member of the news media, or to compel compliance with subpoenas or court orders issued to third parties for communications records or business records of member of the news media, which subpoenas were issued or court orders obtained in the first instance by other Executive Branch departments or agencies. To satisfy the consultation requirement, members of the Department shall submit to the PSEU a memorandum describing the factual and legal background of the matter. Members of the Department may not proceed with any efforts to enforce or compel compliance with any subpoenas or court orders until the Criminal Division has responded in writing to the request for consultation.
At the state level, there are laws in place protecting reporters from being forced to reveal their sources, but they vary from state to state. New York, Ohio, Alaska, and some others have virtually absolute statutory protection. California, Texas and Florida have somewhat weaker statutory protections. A few states, mostly in New England and the Midwest, have no statutory protection, though courts have established protections based on free-press principles. I believe Wyoming is the only state that follows the federal government's anything-goes approach.