I’m new to film, and I am using a Pentax ZX-M. I was shooting some portraits on Kodak UltraMax 36 Exposure film and the film rewinded at 26 instead of 36. Anyone have an idea why my camera did this?
Make sure that you get the film developed!
Then, you need to look at the negative strip to get an idea of what's going on.
Does the negative strip have a really long area at the beginning that is black? If so, you may have simply used up too much film in loading the camera.
Does the negative strip have a really long strip at the end that is clear/unexposed? If so, it appears that your camera rewound the strip early. If this is the case, more troubleshooting needs to be done.
Is the spacing between frames small and uniform? The spacing between frames should be ~2mm and should be the exact same between every frame. Is it?
If you haven't already, get the film developed. There are clues you will find on the developed negatives that might help answer your question. Corey covers the most common issues in this answer.
One other possibility that may not have had anything at all to do with your camera or the way the film was loaded is that Kodak accidentally put a length of film cut for a 24 exposure roll into a film cassette labeled "36". Although extremely rare, it does happen. A normal 24-exposure roll can usually be stretched to 26 frames in many 35mm cameras.
The other answers cover the possibilities well expect perhaps the "mid roll rewind button". It is possible to rewind a roll at any point by depressing a little recessed button located on the side of the camera below the latch that opens the back of the camera. It is small and is not something you can usually depress without using a tool, one is supplied on the original strap, or a paper clip or tip of a pencil.
It is possible that either it was depressed on accident or the button itself is malfunctioning.
Some film rolls had a codebar, a very simple checkboard like a pattern, so some cameras recognize what film is it. Probably the sensors on the camera are dirty or something.
I suspect that it's either what Rafael suggests (a dirty sensor reading the film ISO/exp count code), or that the film was somehow stiff and catching in the spool, so your camera sensed that it had reached the end of the roll. The resistance it registers as "end of roll" needs to be low enough that you don't accidentally pull the film free from the spool. I've had winders break the tape that connects the film and spool (on cameras where a motor drive was a "new thing"). I think manufacturers tweaked the torque after that, because on the later 35mm cameras I had, I'm pretty sure that only happened if I'd self-loaded the film (and had used a poor grade of cellophane tape to attach film to spool).