Reuters has a bit of background:
In 1924, Congress awarded itself the power to obtain tax returns. Previously only the president could disclose them. The change came during a bribery scandal involving federal officials and Wyoming oil field leases known as the Teapot Dome scandal.
The law was crafted in part to help Congress investigate wealthy businessman Andrew Mellon, who was Treasury secretary under Republican President Warren Harding. Like Trump, Mellon kept his business interests while in high public office.
The law says the Treasury secretary “shall furnish” tax returns requested by the chairman of any of three congressional tax panels: the House Ways and Means Committee, the Senate Finance Committee and the Joint Committee on Taxation.
It's confirmed on Wikipedia's page on the Teapon Dome scandal from a different source, albeit also a pretty recent one
Congress subsequently passed legislation, enduring to this day, giving subpœna power to House and Senate for review of tax records of any US citizen without regard to elected or appointed position, nor subject to White House interference
The fact that tax returns were germane to the scandal is covered in the 2013 book Why Coolidge Matters (p. 134). In 1921 Coolidge (availing himself of the laws in force at the time) refused to release the tax returns of some of the people involved in the scandal, which were being investigated by Congress. This conflict lasted years. Coolidge even rejected the Senate's resolution of 12 March 1924 which was asking for the aforementioned tax records (pp. 142-143).
An article by George K. Yin has more details on the 1924 change, :
Congress changed the law in 1924 to address a
separation-of-powers concern. Democratic Rep.
John Nance Garner of Texas, then-ranking member
of the Ways and Means Committee, described the
problem succinctly on the House floor:
Under the present law, if this House passed a
resolution requesting the Secretary of the Treasury to send the returns of John N. Garner to
Congress, he could not do it without violating
the law. The law tells him that he cannot send
it to the House of Representatives without the
direction of the President of the United States.
So the House of Representatives itself has not
the power to get these returns. Now, I think the
House of Representatives ought to have the power
to ask the Secretary of the Treasury for these
returns and get them. [Emphasis added.]
Republican Rep. William Green of Iowa, then chair of the Ways and Means Committee, promptly concurred with Garner’s recommendation. The remaining debate mostly concerned which committees should be given the authority — only the tax committees, or other committees as well — and what protection should be given to the confidential information once Congress obtained it. [...]
Several matters, including two involving possible conflicts of interest, helped bring the
separation-of-powers imbalance to Congress’s attention.
During that period, Congress was investigating the Teapot Dome scandal — the alleged
bribery of government officials in exchange for the
leasing of public oil fields to private interests. As
part of its investigation, Congress sought from
President Coolidge the tax returns of the alleged
principals involved in the scandal, but the president
initially resisted the request. Although Coolidge
ultimately acceded, the experience undoubtedly
made Congress aware of its need to be able to
obtain tax information even without the president’s
permission.
Another matter concerned possible conflicts involving former Treasury Secretary Andrew Mellon,
who continued to own many business interests
while serving in government. Some in Congress
wanted to obtain Mellon’s tax information to learn
how his interests would be affected by tax legislation that Treasury was proposing to Congress.8
Congress was especially exercised by the issue
because of the suspicion that Mellon had previously
revealed to the public the confidential tax information of Republican Sen. James Couzens of Michigan
in connection with a feud between the two men.
Finally, partly as a result of that feud, in early
1924 the Senate began an investigation of the Bureau of Internal Revenue (predecessor to today’s
IRS), and its initial inquiries had been stymied by
the inability of the investigating committee to examine tax returns. Among other things, some
members of Congress wanted to determine if the
Bureau had shown favoritism to Mellon and his
companies.
[...]
The unqualified right was necessary
to correct the separation-of-powers imbalance; because the right of access of the president and the
executive branch to the information was unrestricted, so too should be the legislature’s. Aside
from slight changes in the language, the law remains the same today.
As footnoted there, The Revenue Act of 1924, ch. 234, section 257(a) later became Section 6103(f).
Yin also notes:
The 1924 law also authorized the tax committees
to submit any ‘‘relevant or useful’’ tax information
to the House or Senate, effectively making it public.
In 1976 Congress amended the statute to delete the
words ‘‘relevant or useful.’’ Thus, the current code
authorizes the tax committees to submit any tax
information to the House or Senate. [...]
I argued that because public disclosure of confidential information is more violative of privacy rights
than the mere seizure of the same information by
Congress, Congress’s right to disclose must be
subject at a minimum to the same implicit condition
applicable to its investigative power.
In 1974 Democratic Rep. Wilbur Mills of Arkansas, then-chair of
the JCT [Joint Committee on Taxation], referred to the authority [of the 1924 Act] when the committee, on a bipartisan basis, submitted to the House its
staff report containing and analyzing the confidential tax information of President Nixon. Although
Nixon had already released a substantial amount of
his tax information to the public, Mills referred to
the committee’s special authority perhaps out of an
excess of caution.
In 2014 the Ways and Means
Committee invoked the same authority to release to
the public the tax return information of 51 taxpayers.
FWIW, Dave Camp (R.-Mich.) was the Ways &
Means Committee Chairman in 2014.
As background to the background, the general anti-disclosure provision affecting the IRS (except as amended later) goes back to 1894.
An earlier 1921 attempt by Senator Reed (D.-Mo.) to amend it as make returns “open to inspection by any committee of Congress” was dropped (in part) because Senator Smoot (R.-Ut.), chair of the Senate Finance Committee objected to it on privacy basis, although no official explanation exists on record why Reed dropped his amendment. (There seems to be a little historical discrepancy here because Smoot apparently only became chairman of that committee in 1923, but it's unclear what the trajectory of the Reed amendment was and since it's not too germane to my initial question, I won't try to clarify this bit this any further.)