Several states had trigger laws that automatically banned abortion when Roe v Wade was overturned. Could a state pass a law banning all firearms effective upon the repeal of the Second Amendment?
Yes, a state could pass such a "trigger law". If properly worded, it would probably be enforceable, should the Second Amendment ever be repealed, 0or should the court decisions applying it to the state be overturned or significantly modified.
For the matter of that, a state could pass a law banning all firearms tomorrow. But under Heller and subsequent decisions (particularly McDonald v City of Chicago) of the US Supreme Court and the lower Federal courts, it would be largely if not totally unenforceable.
Nothing stops a state (or Congress, or a local government) from passing unconstitutional laws. But when a government attempts to enforce such laws, the defense may challenge them as unconstitutional, and therefore not valid. If the court accepts that contention, the law is not enforced, and any previous proceedings or penalties under it may be overturned.
I think it quite unlikely that the Congress would pass, and the states ratify, a repeal of the Second Amendment in the foreseeable future, although one never knows for sure what legislators will do.
However, current case law is not incompatible with some laws regulating guns, although a total ban cannot be justified under current case law, as I understand it. For example, Heller includes the statement that:
Like most rights, the right secured by the Second Amendment is not unlimited. [It is] not a right to keep and carry any weapon whatsoever in any manner whatsoever and for whatever purpose. ... nothing in our opinion should be taken to cast doubt on longstanding prohibitions on the possession of firearms by felons and the mentally ill, or laws forbidding the carrying of firearms in sensitive places such as schools and government buildings, or laws imposing conditions and qualifications on the commercial sale of arms.
Later cases have upheld some firearms restrictions.
In United States v. Hayes, 555 U.S. 415, (2009) the Supreme Court upheld a federal statute barring people convicted of domestic violence crimes from owning guns and the use of this law by state regulators.
In United States v. Castleman, 134 S. Ct. 1405 (2014) the judgment, the Supreme Court held that a state conviction for misdemeanor domestic assault qualifies as a “misdemeanor crime of domestic violence” for purposes of possessing a firearm under 18 USC. § 922(g)(9)
Under these precedents, sates can pass and enforce some restrictions on gun ownership and possession, if they so choose.