WASHINGTON — The Justice Department on Friday backed a decision by Treasury Secretary Steven Mnuchin to defy a request from Congress for President Trump’s tax returns on the basis that it lacked “legitimate legislative purpose.”

The department issued a 33-page memo, dated Thursday, that came as House Democrats were preparing a lawsuit as the next step in their effort to gain access to Mr. Trump’s returns. Mr. Mnuchin defied requests made in April and May by the House Ways and Means Committee and refused to comply with a subpoena, setting up a legal battle between the two branches of government.

House Democrats are trying to obtain six years of Mr. Trump’s personal and business tax returns using an obscure provision of the tax code that allows congressional tax-writing committees to get the returns of any taxpayer.

The memo, written by Steven A. Engel, the head of the Office of Legal Counsel, argued that House Democrats, led by Representative Richard E. Neal of Massachusetts, made the request for political purposes with the intention of releasing Mr. Trump’s tax returns. It cast doubt about the formal rationale that the committee used for the request, which Democrats said was for the purpose of examining how the Internal Revenue Service audits presidential tax returns.