I did, as did many of my classmates in the CS department. The important bit is that Stanford does their admissions for the school as a whole. Not the School of Engineering, and certainly not individual departments. Everyone shows up undeclared and has to figure out where they want to be.
Predictably, many people know right away or after freshman year. But there isn't actually a requirement to declare a major until it's time to get a degree. Personally, I was taking classes like an Econ major for two years, and then switched to Computer Science. It took me another year to declare CS as my major, and even then only did so because I was applying to the Masters program (which I never finished).
It's not strictly relevant given that this isn't a class for CS majors, but the answer to your question is that there are many, many CS majors who go on to careers in software who write their first code in their second or third year.