As pablodf76's answer says, this comes from a historical neutralization of the contrasts /ɲ/ vs. /n/ and /ʎ/ vs. /l/ in syllable-final position. (From what I remember, a similar neutralization happened in a certain stage of French, although French has different examples of alternation because it developed /ɲ/ and /ʎ/ from different sources, and of course French and Spanish words often have different syllable structures.)
The neutralized coda consonant is typically non-palatal, except for if it becomes palatalized by assimilation to a following palatal consonant (circumstances where that can happen are described on this web page: Neutralization in Spanish).
Other examples of alternations between /ɲ/, /ʎ/ and /n/, /l/
I don't know of any further examples of alternation between masculine and feminine words other than the ones mentioned in the question and in pablodf76's answer. I found an article, "Spanish 'Depalatalization': The Synchronic, Diachronic and Perception Perspectives", by Ryan M. Bessett and Sonia Colina, that gives examples of this alternation in other pairs of related words, such as
(p. 224-225; Bessett and Colina attribute these examples to Pensado, 1997, p. 595-596 and Lloret & Mascaró 2006, p. 77-78)
"When diachrony meets synchrony: Phonological change, phonological variation and Optimal Paradigms", by Clàudia Pons-Moll, mentions that aquel and el have a palatal consonant not only in their feminine forms, but also in their masculine plural forms: aquellos and ellos (p. 18). In contrast, don and desdén have plurals with non-palatal [n]: dones and desdenes.
There seems to be a lot of linguistic literature about how exactly to analyze the historical patterns of alternation, and to what extent the alternation is related to currently active as opposed to only historical rules of the Spanish sound system. If you're interested in a deeper look at that kind of thing, you could read either of the two linked papers or some of the works that they cite. (I have only skimmed them.)