You can purchase your militia firearm after your service has ended but it must be converted to semi-automatic and you have to apply for a permit - a semi-automatic firearm would fall under the "may-issue" permits which requires justification for why you need said firearm, and it seems that ammunition falls under the same rules. It'd be great if a Swiss person could chime in since I don't know anything more than what I've gleaned from this article.
[0]: https://en.wikipedia.org/wiki/Firearms_regulation_in_Switzer...
"Until now, hundreds of key roads and bridges across Switzerland have held stores of explosives for use in the event of invasion. The policy was developed during the Cold War, because of fears of an attack by Warsaw Pact countries, eight communist states of Central and Eastern Europe." [1]https://www.swissinfo.ch/eng/cold-war-defence_army-to-find-a...
Sometimes, your ability to have gun is dependent also on you finishing the service - tho I think that is mostly to stop people from dodging the draft. (In Iran, you are not allowed to have passport without military service. They can deny you driver's license too.)
Edit: Spelling