A better explanation is the latin origin of the word diéus, which is masculine
It's "
dies" -- and the word in Latin was used sometimes as a masculine, sometimes as a feminine.
This resolved as a masculine word in some Romance languages, and a feminine in others. Usually masculine, but for example the word in Romanian became
zi, which is a feminine ; and in old French, the word
diemaine (meaning both Sunday, modern
dimanche, and tomorrow, modern
demain) could be either masculine or feminine.
And take note that the Credo, which is Late Latin, has
Et resurrexit tertia die ; so is using it in the feminine.
And there's a traditional mountain festival of the French Alps called
La Belle Dimanche, so by exception to modern French in the feminine.
But
dies mostly became masculine in the later Romance forms, from being mostly used in masculine in the Latin.
But it was not a word of the typically feminine first declension of Latin, that the -a nouns in Spanish are derived from, but the fifth declension which had words of either grammatical gender (and IIRC not neuter), and that is the main reason why it doesn't follow the typical rule of feminine -a from Latin first declension in -a, masculine in -o from Latin second declension in -u.
Words of the fifth declension evolved fairly arbitrarily into their later Romance equivalents, because the whole of the declension had been scrapped in the ordinary language of the Late Latin period, and was preserved only in the more erudite and literary Classical forms.