"Med-" is a common prefix used quite the way English might use co- to express doing something together. Compare it for example to medarbetare, meaning co-worker, collaborator, colleague.
"Borgare", a loanword from medieval low German borgere, comes from the name of one of the four estates of the realm back in older times when society was divided into four estates. The borgare were the town-dwellers and merchants, and the others of the four estates were nobility, clergy and farmers. With time, the notion of "borgare" expanded to refer to citizens rather than just the noteworthy townspeople, and med- was added. Compare it for example to the German word Bürger and the Dutch burger, both of them also meaning "citizen".
If we want to go back even further, we can see that "borgare" is formed from "borg + are". Borg in itself comes from a meaning of a high place that is easily defended, and later came to acquire its modern meaning of "castle". Since cities often grew around a local fortification, "borg" also came to denote a city, from whence the "borg" in medborgare comes.
In German we have the word "Mitbürger" which seems close to "medborgare".
I feel like there is a little difference between "Mitbürger" and "Bürger". A "Mitbürger" would be someone who is part of / takes part in your local society (a friendly neighbor, someone who participate in a spots club, etc.).
A "Bürger" would be someone who has official citizenship of a country or is a registered inhabitant of a city. Is this in Swedish also the case?
I looked it up and it was defined as “har lagligt skydd av den och lagliga skyldigheter mot den” which google translate tells me is something like “having legal protections by and legal obligations towards” the State; so I would say likely not, it sounds like a formal definition of citizen.
'a fellow citizen is a citizen of the same state as the person speaking, writing, or being referred to' – it shouldn't be accepted, because medborgare only means 'citizen'.
In many contexts in real life, the difference may not matter of course. But taken out of context, 'Are they fellow citizens?' should be Är de medborgare i samma … + whatever.
I've been confused by that in German too. borgare in Swedish is either a political term or used historically as in the four classes of society (adel, präster, borgare och bönder see https://sv.wikipedia.org/wiki/St%C3%A5nd_(samh%C3%A4llsklass))