When is g pronounced [g] and when is it pronounced [j]? Also, when is k pronounced with a hard k?
In middle school we learn that the vowels are split into ”hard” and ”soft” vowels. The ”hard” vowels are a, o, u, å and the soft vowels are e, i, y, ä, ö. In reality it has to do which vowels are pronounced at the back of the mouth and which ones at the front. But the logic is that it stays [g] before the hard ones and become [j] (softened) before the soft ones.
Because of historical reasons the consonants before the front vowels became more fronted as well, since it’s easier to say front+front. This happened gradually, and that’s why we have a split. This affects, e.g. [g] which turns into [j], [k] which turns into [ɕ] (like sh pretty much), and sk which becomes the ”sje-sound”.
This does not apply to loan words, since they were borrowed after this gradual fronting change (it’s called palatalisation if you want to look it up)!
Therefore, we have both kör [ɕœːr] (shurr) ’drive!’ and kör [kœːr] (kurr) ’choir’, since the latter was borrowed from French.
This is also the reason why the consonant clusters that end on -j are pronounced as they are since the -j also caused this softening (palatalisation). That’s why, sj, skj, stj are pronounced [ɧ] (the sje-sound, or the hwoo-sound) and tj and kj are pronounced [ɕ] (sh).