Personal background
I include the following in order to establish my bona fides with respect to both secondary and post-secondary education.
My bachelors degree is in mathematics, with a minor in secondary education. I was certified by the State of Nevada to teach mathematics at the middle school and high school levels (6th grade and above in the district I worked in). After completing my credential, I spent a couple of years going from one long-term substitute job to another—this was just after the housing crash in 2008, property values had dropped dramatically, and the district had no money to hire new teachers, so they instituted a hiring freeze and employed long-term subs to fill the gaps.
I eventually gave up on the idea of a teaching position with security of employment—both because it seemed like the district was not going to fill those positions, and because there were some aspects of the job that, it turns out, I really didn't like.
I went back to school and earned a masters, and then a PhD, in mathematics. I defended my thesis in the spring of 2020, which gives you some idea of what the academic job market looked like (COVID shut things down), and I had no desire to get on the postdoc treadmill (I am somewhat older than most of my grad school cohort, and needed long-term security). I applied for many tenure-track positions, as well as teaching positions (primarily at community colleges).
I am now a member of the faculty at a community college in northern Arizona and, having completed three years here, am on a "continuing contract" (e.g. I have "tenure", though the state legislature does not recognize the existence of such an institution).
Post PhD employment in academia
Someone with a PhD has a number of options in academia, both in terms of short-term contract or "gig" work, and in terms of positions which promise more long-term security of employment. The general categories of employment which offer more long-term security are, broadly speaking, those listed below. Note that this is not exhasutive.
Professorships
As noted in the other answers, most professorships are research positions, rather than teaching positions. At R1 universities, the ladder faculty are typically required to teach only two or three courses in a term (sometimes even less), and are judged much more on their research output than on their teaching quality. Indeed, it is possible that teaching, while required, will not really be evaluated in any meaningful way, nor included in tenure or promotion.
I would expect that taking time off to teach will hurt, rather than help, one's prospects with respect to this kind of position. While a hiring committee will be happy to see evidence of teaching ability (and may require it, despite the fact that it is often not valued once one actually has the job), they are not going to want to hire someone who has not published in the last several years. The cost of not producing papers is likely to outweigh the benefits of obtaining more teaching experience.
At other types of institutions (e.g. small, private, liberal arts schools; bachelors-granting state institutions; etc.), there is still generally some expectation that those in tenure-track positions will conduct research and publish papers. Teaching experience in these positions is more valued, and teaching high school may help but, again, the lack of research output might hurt more.
If this is the kind of position you are looking for, I would recommend very much against taking time out of academia to teach high school.
Teaching positions
Many institutions (R1 and otherwise) have teaching positions, with titles like "professor of instruction" or "lecturer". These are sometimes ladder positions (i.e. tenured), but are often not. As such, the people who take these positions are often excluded from certain faculty functions, e.g. they may not have a voice in the faculty senate, or may have little representation in the administration of the department. Moreover, these positions often pay significantly less than research positions (though, for example, I have a good friend with a "professor of teaching" title who is considered ladder-faculty, and has all the rights and benefits of someone without the "of teaching").
On the other hand, all that is typically expected of such a position is teaching and, perhaps, curriculum development. Some in this kind of position is probably going to be teaching mostly lower-division classes (e.g. precalculus and calculus in a math department), but might sometimes have the opportunity to teach more advanced or focused material (e.g. real analysis or abstract algebra).
These kinds of positions used to be somewhat rare, or poorly compensated. However, my impression is that institutions are starting to hire more teaching faculty, and that there may be something of a market for folk who can fill these roles (though this is only my impression—I could be way off.
If this is the kind job you are looking for, taking time out of academia to teach high school might help. The lack of research output probably won't hurt.
Community college positions
Another option is to teach community college. The advantage is that these institutions focus almost entirely on teaching (we have a total faculty of around 80, probably around 40 on the non-vocational, non-remedial side of the house; collectively, the faculty have published three or four papers in the time that I have been here), and research output is not expected (or, often, even valued).
At many community colleges, the minimum requirement for a faculty position is a masters degree, rather than a PhD, and hiring committees will often see a PhD as being an over qualification. There is an impression among some folk that having a PhD indicates that one is too much of an ivory-tower egghead, and can't speak well to students. Having spent time teaching high school could be seen as an indication of commitment to teaching and might be viewed positively.
If you are looking for this kind of position, taking time out of academia to teach high school might be a good idea.
Certification
Something which others are not addressing, so far as I can tell, is the certification process. In the United States, it is very difficult to get a high school teaching position without a secondary education certification. Obtaining such a certification usually requires at least an extra year of coursework, plus a semester long internship (student teaching). There are very few public school positions which don't require this certification process, though it is sometimes possible to get a provisional certification (these are typically temporary, and expire if you do not complete the standard certification process within two or three years).
Private and charter schools can be a bit fast and loose with certification (since there is generally no requirement that teachers be certified), and there are some exceptional and/or specialized public schools which do not require certification, but certification is often still valued, meaning that an uncertified instructor may have a harder time finding a job.
If the plan is to teach high school for a period of time, one has to go into their education with that plan in mind. Start working towards certification now.
Timing
Taking time off after completing a PhD in order to teach high school is very likely to be detrimental to the prospect of obtaining a ladder position in "mainstream" academia. Most of those positions require publication, and you won't be publishing while teaching high school (let's be real here; teaching high school is hard, and you aren't going to have time to research; there are probably some exceptions to this, but don't plan your life around be an exception).
Moreover, you are young, and just starting your career. It doesn't seem reasonable to me to plan so far into the future. In the next year, you might decide that you hate mathematics. Or you might decide that you hate teaching. Or that you hate research. Or you might fall in love and follow a partner where ever their career takes them, while you stay at home and raise the kids. It is good to have long term plans, but you should always be flexible, and recognize that your plans will very likely change.
For what it is worth, I tend to make plans with 2-, 5-, and 10-year horizons. I have never gotten to the end of a 2-year plan without major modification.
Having said all of that, the following path may be more advisable, in terms of not locking yourself out of either secondary teaching positions or mainstream academic positions.
While still an undergraduate, start working towards secondary certification. If your institution has a certification program, talk to an advisor there, and see what they have to say. Avoid saying that consider high school teaching to be a temporary postion—focus on the idea that you are interested in teaching, and that you are interested in becoming a better teaching in furtherance of your long-term goal of an academic teaching position.
Note that this is very likely to add an extra year to your bachelors program (though it might not—just be prepared for that news).
After completing your bachelors, teach high school (if you can). Really commit to that job—don't view it as a short-term gig, since people will pick up on short-timer-ism, and are not likely to be happy about it.
If, after teaching high school for a while, you are convinced that you still want to pursue graduate school, apply. Graduate programs are typically much more open to students who have taken time off to do other things than are hiring committees looking for tenure-track faculty. Do note, however, that you might have more difficulty getting into an "elite" program, as they, too, will be focused on research.
After completing a PhD (or masters, if you decide that a PhD isn't for you), you can make decisions about where to go next. Maybe you will want to go back to teaching high school!
The advantage of this plan of action is that (1) you get an understanding of the theory of instruction in addition to teaching experience, and (2) you still get to put that teaching experience on your CV when you start looking for academic positions.