If government officials attempt to enforce an unconstitutional law, people whom the law effects can still sue those officials, despite their sovereign immunity because in that instance, they are not acting on behalf of the state.
Minnesota imposed high penalties on railroads that violated state limits on what they could charge within the state. The shareholders of Northern Pacific Railway said that this law violated the Fourteenth Amendment and the Dormant Commerce Clause. They also sued Edward T. Young, the Attorney General of Minnesota, to enjoin him from enforcing the law. Young said that the 11th Amendment meant the Court did not have jurisdiction to hear the case, because it prevents states from being sued by citizens of other states. The federal circuit court granted the injunction, and Young filed in Minnesota state court to compel the railroads to adhere to the statute.
May out-of-state railroads file an injunctive action against a state official over in-state tariffs, alleging that the Commerce Clause bars the tariffs?
The Eleventh Amendment prohibits the commencement or prosecution of any suit against one of the United States by citizens of another State or citizens or subjects of any foreign State. Although the state itself cannot be sued, there is no prohibition on enjoining a state official as an individual who is carrying out tasks on behalf of the state. When an official does something unconstitutional, it is therefore not acting on behalf of the state and he/she becomes another citizen who can be enjoined.