It's caused by a prion, a misfolded protein with the particular characteristic of forcing proteins folded correctly to also get misfolded.
It's not "caused by" cattle consuming remains of other cattle, but there aren't other ways for a complex protein to be ingested and retain it's shape* other than consuming raw remains containing that protein.
Basically, another cow (or a goat) develops a misfolded prion protein that spreads itself by misfolding other proteins. If another cow eats said misfolded protein, it will start doing the same thing within the new host. The first misfolded protein in this chain is just a random event that can happen to any cow, at any moment. There are intracellular mechanisms to detect misfolded proteins and revert them, but if they all fail and the protein is misfolded in a very unlucky way, you get mad cow disease (or the other couple prion diseases known so far).
*: with mad cow disease cooking/heating actually is often not enough to completely disarm the misfolded prion proteins, as they form dense agglomerations of sheets of misfolded proteins.