Isn’t が meant to be the person doing something? If that’s the case, shouldn’t this mean that mary is the one that likes sam and not the other way around? Since sam is the topic of the sentence, then aren’t we talking about how mary likes sam?
[I’m also still a beginner…so anyone, please feel free to correct me if I’m wrong]
From what I understand, the literal translation of 好き is “likeable”, but it sounds more natural to translate it as “like” in English.
サムはマリーが好き → the literal translation would be “As for Sam, Mary is likeable” (aka Sam likes Mary).
Vice versa, マリーはサムがすき → “As for Mary, Sam is likeable” (aka Mary likes Sam).
This is an AがBだ sentence structure, which in short means that A is B. だ is a copula. As @Seirios359 said, this literally means Mary is likeable. Yes, she is doing the action of being likeable, although 好き is a noun, so let’s not take this literally. For whom though is she being likeable? For the guy in the topic of the sentence.
There’s a bunch of constructions in Japanese that use a double が construction, such as 好き/嫌い, 分かる, potential verbs etc.
The sentence “who is it that likes the cat?” can thus be translated as 誰が猫が好きですか?
Of course, in many cases, one of these が phrases will become a topic, so the が is replaced by は, so you would have
私が猫が好きです - it’s me who likes the cat (e.g. answering the above question), but
私は猫が好きです - I like the cat (general statement about myself)
It’s probably best to memorise those double が constructions as a bit of a special case that can’t be neatly explained with the traditional subject/object distinction.