It actually has the same root as the Latin term equus, both coming from the PIE *ʔékʲwos. For alfalfa, it went by way of Persian aspast, apparently the palatovelar [kʲ] becoming [s] and the labiovelar [w] in that environment interestingly becoming [p]. (I’m assuming the -[t] is a grammatical thing from Persian.) Remember that an approximant sound can potentially become a fricative or a stop. It’s important to point out that in this PIE root this is not a labiovelar [kw], but the sequence of a palatalized (or possibly plain velar) followed by a [w]. In all of the reflexes for *ʔékʲwos then, if [w] changed, it either became a [v] or [p] or it went away, so we don’t see [w] becoming a velar.
The later Persian form aspest was borrowed into Arabic where it picked up the definite article prefix al– and underwent a transformation that looks like some reduplication was involved: al-fisˤfisˤ The first syllable as– may have been discarded (subconsciously) as sounding too much like the article. That would give us *past and since there’s no [p] in Arabic that falls to the next voiceless labialoid sound [f] and something about Arabic at this time or the sound of the secondary, tertiary articulation / phonetic minutiae of the Persian –st# to the Arabic ear led [st] to become a pharyngealized s. So it was
(our article)(unnecessary repetition of article)(labialoid)(vowel)(s)(something else we’ll call it emphatic)
yielding *al-asfisˤ which then was reduplicated to *al-fisˤfisˤ, possibly to fill in the timing of the word and/or to feasibly mimic the lost [as] by means of differentiation. There also could have been an intermediate form *al-isfisˤ and the similarity of the final syllable to the previous one led them to assimilate. (And reduplication seems fitting for casually or even dismissively waving at that horse food stuff. Horses were heavily used in Arabic-speaking regions so they would have been commonplace and familiarity tends to breed a sort of phonological contempt/ennui and understatedly endearing creativity, i.e. you get bored saying the same thing over and over again, so you change it by processes it beyond systematic, regular sound change.)
Then Spanish, the great vehicle of Arabic for Europe, further changed our now recognizable form to [alfalfes]. Again we see some assimilation with the -[al] sequence being repeated in the second syllable. This suggests there may have been an intermediate form more like the Arabic of [alfesfes] and the -[sf]- sequence was too much for the Spanish tongue. Later the final [s] was lost and we have the form that looks familiar to us today.
and horse ultimately came from the same word.
That’s quite a statement for word relationships and the process of neologism (or neology, as the practice of using a neologism).
But now that we’ve seen the phonological pathway for that, ‘horse’ and ‘horse food’ having the same root doesn’t sound so crazy.