I've been led to believe that the Attorney General is the US government's lawyer in the Supreme Court. On the other hand a lot of federal policies are going to be inherited from a previous administration belonging to the other party. When this happens, can the president's party not just push for the Supreme Court to rule the policy unconstitutional, while the AG gives a really bad or no defence in court? And if this is possible, does it effectively mean that any policy with even slightly questionable constitutional legitimacy will die as soon as the white house changes hands?
The US Solicitor General is the government's top lawyer before the Supreme Court and lower federal courts. Prior to 1870, the creation of the office, the Attorney General filled this role. The Solicitor General is part of the Department of Justice, with some career DOJ attorneys supporting, but the office is appointed by the President directly.
The Solicitor General would be unlikely to present an intentionally poor defense of a case. The question of whether the President and USSG may decline to defend a law is controversial, with some arguing there is an obligation to defend all federal laws in court and others arguing that there is an obligation to exercise independent judgment and constitutional discretion. Some argue a middle ground position. The Obama Administration enforced the Defense of Marriage Act, but refused to defend it in court, striking a compromise of sorts.
As a practical matter, all recent Presidents have declined to defend some laws. I will quote at length a footnote:
Every recent administration has refused to defend some laws that it believed were unconstitutional. President Ronald Reagan, for instance, successfully challenged (rather than merely refused to defend) a statute that allowed either House of Congress to invalidate an administrative decision made by the Executive Branch. Seth P. Waxman, Defending Congress, 79 N.C. L. Rev. 1073, 1084 (2001) (link). President George H. W. Bush refused to defend the constitutionality of provisions in the Cable Television Act of 1992 that required cable companies to carry certain content. Id. at 1084. The Department of Justice under President Bill Clinton refused to defend the constitutionality of a law that sought to limit rights under the Supreme Court's decision in Miranda v. Arizona, 384 U.S. 436 (1966) (link). Waxman, supra, at 1087–88. In 2004, the Department of Justice under President George W. Bush refused to defend a federal law prohibiting the placement of marijuana reform ads on public transportation systems. Letter from Paul Clement, Solicitor Gen., U.S. Dep't of Justice, to Patricia Mack Bryant, Senate Legal Counsel, U.S. Senate (Dec. 23, 2004) (link); see also Letter from Andrew Fois, Assistant Att'y Gen., U.S. Dep't of Justice, to Senator Orrin G. Hatch, Chairman, Comm. on the Judiciary 8 (March 22, 1996) (compiling a list showing forty-five instances between 1975 and 1993 in which the Department of Justice communicated to Congress that it was declining to defend or enforce a statute) (link).
The Clinton Administration assembled a list, mentioned in the above blockquote, going back to 1946 finding similar instances where the Administration declined to defend laws in court.
So while the right of discretion is quite controversial, it's a well-established practice that at least in some cases it is warranted and constitutionally permissible. However, this does not mean that administrations abandon all laws they dislike, and often administrations enforce and defend laws passed by the other party. Typically, such laws are not open to constitutional challenge or the challenge is made in a way that unifies the parties. A number of constitutional challenges would limit government power generally, and so whichever party holds office tends to have a strong interest in not seeing its power limited.
As a general principle, the discretion to abandon unconstitutional laws is simply another expression of checks and balances. Congress may be able to pass laws, but the President has at least some discretion to abandon their defense in court. This is a rarely used power, but it has a corollary to the veto power.