Lately, I've started noticing how some Spanish nouns are merely past-participles of verbs (with the addition of a "-ado/-ada" suffix), and that those verbs are sometimes derived from other nouns by adding an agency prefix (like how "Em-" is added to "barca"/"boat" to make "embarcar"/"get on a boat").
But I've noticed something odd with what happens to the genders when this happens in a few words, specifically: "empanada" and "emparedado"
"Empanada" seems to come from "empanar" (to wrap in bread), which must come from "pan" (bread) and "Emparedado" seems to come from "emparedar" (to wall in), which much come from "pared" (wall)
What I find curious is that the gender changes during this: "pan" (male) gives rise to "empanada" (female), while... "pared" (female) gives rise to "emparedado" (male)
Now, the gender doesn't always switch. For example: "papel" (male) gives rise to "empapelado" (male)
So, I was just wondering, are there any guidelines to whether the derived word becomes male or female? Does it depend, at all, upon the word it is derived from?