Walt's life has been a failure in many ways. Although his (extended) family is a good family (people are flawed but not malevolent), he had so much potential compared to where he ended up.
This is the foundation of the show's plot. Walt starts the meth empire not only for the money (that's just the justification he uses), but also because he wants to prove to himself and the world that he is a force to be reckoned with.
This means that before he starts the meth empire, he must therefore be leading a pathetic life where his potential is wasted. His job as a teacher tries to illustrate that point.
But is it ever explained why he is teaching chemistry in a high school?
Teaching is often considered to be a "lesser" job compared to practicing.
Your question already implies that you are aware of this: why is Walt merely teaching chemistry, and not practicing chemistry professionally?
So the most direct answer to your question would be because the plot needed the story to start off with Walt suddenly realizing that he is leading a pathetic life. The teaching job illustrates the sad life he is leading.
Please note that the teaching was not the sole indication of Walt's pathetic life (as he saw it).
- In the opening scene (breakfast at home), it is made clear that the water heater is broken, and that it has been the case for a long time. Walt is clearly not doing well financially.
- In somewhat of an ironic twist, Walt is also a bad teacher. Not because he is incompetent, but because he is overqualified to the point of forgetting to explain things that are obvious to him but not the students. This presents itself as Walt often having backtrack on his statements to clarify, which makes it seems as if he doesn't know what he's talking about (to a layman). From the pilot: "Chemistry is the study of what? Chemicals! No! Chemistry is... Well, technically, chemistry is the study of matter. But I prefer to see it as the study of change." Walt can't even agree on a description for his own field. Is it the study of chemicals, matter, or change? He tries to make distinctions that his students cannot comprehend. (Later in the show, we see Walt making the same mistake with Jesse. He explains things as he understands them, not how Jesse understands them).
- Walt has to work two jobs and is working himself to death for a family life where he isn't even allowed to have a plate of non-vegan bacon.
- Walt doesn't even get the minor authority over his own students, as he has to suffer the humiliation of cleaning their cars in his second job.
- The world shits on Walt. Skyler babies him and Hank considers Walt less manly than him (Hank is not malevolent about it and doesn't even mean to, but he does override Walt in terms of masculinity). I also seem to remember an early scene where Skyler suggested Walt asks Hank for help with what should have been an easy household chore. This makes Walt feel emasculated by his own wife.
- In general, the world sees Walt as the disappointment he grew up to be, rather than the genius he actually is. This very much drives Walt's need to show the world that he is better than they think of him.
- Out of universe, the car that Walt drives is considered well built, but it never sold well, for no reason other than it never being popular. Similar to Walt, it had potential but ended up as being a failure to start.
If you want to dig deeper into the question, as to how his life became so devoid of potential, that is mostly a matter of bad luck.
Walt did not do anything specific to deserve it. He made some bad decisions (e.g. leaving Grey Matter), but it is important to note that this decision can only be called bad in hindsight. At the time, Walt could not have known that Grey Matter would become a highly succesful company.
He didn't even leave Grey Matter for professional reasons. It has to do with Gretchen on a romantic level.
But the most important part is that his decision, while essential to his lack of financial success in the future, was not a bad decision at the time he made the decision.
For all he knew at the time, he could have stayed with Grey Matter, which would have remained to be a failing business, and missed out on some golden opportunities because he was too loyal to his failing business.
Walt zigged, when he should've zagged (just like the rest of the world). The fact that it was outside of Walt's control only contributes to how much it annoys him to be a failure, and how he feels the world has wronged him.