It is a question that many people do not ask themselves until the situation is already over: what happens to my permission if I separate? The answer depends on the type of permit, how long you've been in Switzerland, and who you were married to.
If you have a B permit linked to a Swiss spouse or with a C permit, the basic situation is as follows. If the marriage lasted at least three years and you are well integrated, you can keep your residence permit even if you get divorced. If the marriage lasted less than three years, you only retain the permit if you can show that a return to your home country would result in a “case of severe rigidity” - dependent children in Switzerland, documented domestic violence, or other exceptional circumstances. The legal basis is Article 50 of the Law on Foreigners and Integration (LEI).
If you already have the C permit (permanent residence), the divorce changes virtually nothing. Permit C is not dependent on marital status and cannot be withdrawn for that reason. If you have a B work permit, the situation is also different: the permit was linked to your job, not your partner, so divorce does not directly affect you.
What complicates things is time. Who has been married for two years, thinking that the permit is already secured, and separates before reaching three, may find himself in a more fragile situation than he expected. It is advisable to consult with the migration service of the corresponding canton before making decisions. Deadlines and criteria vary slightly by canton.