He doesn't turn into a horse, that's Beta Ray Bill. He's an alien (a Korbinite, if you want to get specific) whose home planet was destroyed. His people went into hibernation while a sentient ship named Skuttlebutt searched for a new home for them. Bill was appointed their protector and had his consciousness transferred into a powerful body that was a combination of robotics and the most ferocious creature on their old planet, which happened to resemble an Earth horse.
Skuttlebutt skirted a bit too close to Earth and Thor did Nick Fury a favor by going out to investigate. He and Bill fight and Bill proved himself worthy of lifting Mjolnir, so Odin held a deathmatch to determine who would get the hammer. Bill won (although Odin kind of rigged the fight) but saved Thor's life in the process, proving that his power was tempered by mercy and he really deserved Thor's power. So Odin created Stormbreaker, a duplicate of Mjolnir with all the same powers, only it magically enabled Bill to return to his natural Korbinite body as well (he hated being the cyborg but accepted it to protect his people), and he and Thor developed a strong, almost brotherly bond.