-과 and -와 is a same connecting particle.
-과 is attached to nouns in which the last letter is a consonant and
-와 is attached to nouns in which the last letter is a vowel
The same rule applies to -은/-는, -을/-를, -이/-가 etc.
The original form is 와.
ㄱ sound is added for pronouncing fluently after a word that end in a consonant.
Similar transition can be found in Mongolian language also.
ex)
책 + 와 => 책과
친구 + 와 => 친구와