In the film Marty’s and Doc’s backstory remains unexplained.
However, in 2011 co-writer and co-creator Bob Gale actually answered the question online himself.
So for anyone interested…
Marty McFly had been raised his whole life being told that Emmett Brown was a dangerous lunatic. So at 13 or 14, being and I quote, “a red-blooded teenage boy” he decided to find out if there was any truth to these stories. So he broke into Doc Brown’s house where he found a series of Brown’s experiments, and became fascinated by them.
Brown caught him, but rather than being upset by Marty’s breaking and entering, he was just glad someone took an interest in his work.
At this point, Marty decided Doc was an interesting guy and not the scary nut everyone made him out to be, and they formed a friendship.
But, not to put too fine a point on it, everyone was right, and Marty was wrong.
Doc really is a dangerous lunatic – agreeing to build a nuclear bomb for Libyan terrorists to steal plutonium from them, for instance, is really, dangerously crazy. And that’s just one lunatic thing we know he did.
Hell, just storing plutonium in a house in rural California probably qualifies as yet another bat-shit crazy, dangerous stunt to begin with. God knows how many rads he and Marty were exposed to just being around that stuff, or how quickly they would develop cancer as a result. They’re both lucky that neither they nor Einstein died of radiation sickness.