Sweden's grid is already mostly decarbonized thanks to abundant hydro, but they participate in the European market for electricity and the rest of Europe is still behind Sweden.
In the US, it’s to make sure shortsighted investments in fossil fuels pay off (they cap rooftop solar below what makes financial sense for individuals so that rates stay high) or to shelter investors from criminal negligence. (e.g., when PG&E embezzles maintenance funds then burns towns down or blows up city blocks, its customers pay for damages. Lots of people die, but no one goes to jail.)
Sweden used to have twice as many nuclear reactors as it does today. There's also more export capacity, and for Germany anything from Sweden is considered cheap.