First of all, does it even matter? I always assumed it did, so they can see the academic side of the student in the particular subject which is related to the major applying for. But since the admissions are holistic, does this hold true or are they just trying to look for positive sides of the applicant as a “person” and don’t care what subject the recommender taught?
And if it does matter, should I ask a math teacher to for a letter for a CS program? Teacher who taught me CS is out of reach and thought math was most relevant to CS. My other options are physics, chemistry, or history teacher. And for engineering programs should I include a LoR from the physics teacher?
Pick your strongest recommendations. Some schools are specific, so look carefully at their websites. I’d pick math over CS - math is a core subject. Schools know the odds are high you will change your major, so aren’t locked into the idea that you need recommendations from your proposed subject areas. Also, physics isn’t that relevant to engineering. But for a proposed STEM major, I’d say at least one STEM recommender is required.
My kid had one from a history teacher and one from a math teacher. Got in everyplace she applied. Was a physics major.
Physics is highly relevant to engineering. Most engineering is rooted substantially in the applications of physics. Do you really know what you are talking about?
The most important things is that you pick the two teachers who can best discuss your academic and personal strengths. I’d include at least one STEM teacher given your interests. And if all other things are equal and you are not given other instructions, consider asking one STEM and one humanities teacher.