tl;dr
In isolation, 18 U.S.C. § 922(g)(4) appears to operate as a permanent ban, though affected persons may seek permits and appeal a subsequent denial.
Background
18 U.S.C. § 922(d) is the law on sales:
It shall be unlawful for any person to sell or otherwise dispose of any firearm or ammunition to any person knowing or having reasonable cause to believe that such person ... (4) has been adjudicated as a mental defective or has been committed to any mental institution[.]
18 U.S.C. § 922(g) is the law on possession:
It shall be unlawful for any person ... (4) who has been adjudicated as a mental defective or who has been committed to a mental institution ... to ship or transport in interstate or foreign commerce, or possess in or affecting commerce, any firearm or ammunition; or to receive any firearm or ammunition which has been shipped or transported in interstate or foreign commerce.
The wording of the laws is past tense—any person who "has been" committed—meaning that there's a strong textual case for a lifetime ban. While not binding, the Supreme Court seems to agree:
A person adjudicated as a mental defective may later be adjudged competent, and a person committed to a mental institution later may be deemed cured and released. Yet Congress made no exception for subsequent curative events. The past adjudication or commitment disqualifies. Congress obviously felt that such a person, though unfortunate, was too much of a risk to be allowed firearms privileges.
Dickerson v. New Banner Inst., 460 U.S. 103, 116 (1983) (not binding because the case dealt only with persons who had served lengthy prison terms rather than those who had been involuntarily committed).
More importantly, Congress seems to agree. It allows states to receive certain federal grants only if they establish programs that provide an avenue for "relief" from the lifetime ban of §§ 922(d)(4), 922(g)(4). For example, § 105 of the NICS Improvement Amendments Act of 2007, 121 Stat. 2559, describes a state's program as qualifying in the following way:
(a) Program Described.— A relief from disabilities program is implemented by a State in accordance with this section if the program—
(1) permits a person who, pursuant to State law, has been adjudicated as described in subsection (g)(4) of section 922 of title 18, United States Code, or has been committed to a mental institution, to apply to the State for relief from the disabilities imposed by subsections (d)(4) and (g)(4) of such section by reason of the adjudication or commitment;
(2) provides that a State court, board, commission, or other lawful authority shall grant the relief, pursuant to State law and in accordance with the principles of due process, if the circumstances regarding the disabilities referred to in paragraph (1), and the person's record and reputation, are such that the person will not be likely to act in a manner dangerous to public safety and that the granting of the relief would not be contrary to the public interest; and
(3) permits a person whose application for the relief is denied to file a petition with the State court of appropriate jurisdiction for a de novo judicial review of the denial.
(b) Authority To Provide Relief From Certain Disabilities With Respect to Firearms.— If, under a State relief from disabilities program implemented in accordance with this section, an application for relief referred to in subsection (a)(1) of this section is granted with respect to an adjudication or a commitment to a mental institution or based upon a removal of a record under section 102(c)(1)(B), the adjudication or commitment, as the case may be, is deemed not to have occurred for purposes of subsections (d)(4) and (g)(4) of section 922 of title 18, United States Code.
Michigan, however, wasn't one of the states that implemented a relief program. And this brings us to Tyler v. Hillsdale County Sherrif's Dept., 837 F.3d 678 (2016). Therein a Michigan resident who wanted to purchase a firearm was deemed ineligible by the Sheriff's Office because of an involuntary commitment related to a depressive episode during a divorce a couple decades earlier. On appealing to the FBI's NICS Section, he was denied. His case became a federal one and eventually reached the Court of Appeals for the Sixth Circuit in Tyler. Because Michigan's lack of a relief program made § 922(g)(4) operate as a permanent ban on Tyler's ability to possess a firearm, they ordered a lower court to determine whether § 922(g)(4) was unconstitutional as it applied to Tyler's specific circumstances. This gave Tyler the opportunity to argue that he didn't present a danger to the public.