Quite simply, you get doors of nonstandard size via special order.
When looking at door replacement, measure the size of the door slab itself, not the frame. If you have e.g. a 30 inch door, that means the rectangular piece of wood that is the door itself is 30 inches wide (and likely 80 inches tall which has been standard in the USA for decades, although that can vary as well). A 30 inch door may require a 30.5 inch gap measured from edge to edge of the frame (note: this is an example, I don't know the actual clearance). If you try installing a 30.5" door slab into a frame with exactly 30.5" of clearance, you will not be able to close it. Doors have thickness, and the hinges need a little bit of wiggle room as they swing the door out.
Your question is slightly ambiguous about what exactly you are trying to replace, so I will cover both options here.
Replacing the door slabs: simply measure the doors themselves. Measure the width, height, thickness, the dimensions and locations of the hinge plates, location of the latch (the part that sticks out of the side and keeps it closed), etc.
Replacing the door along with the jamb, i.e. a complete pre-hung door. Measure the width and height of the door slab, and also the rough-in size. Do this by removing the door casing carefully to avoid damaging the surrounding area, and removing any other obstructions that prevent viewing the underlying wall framing. You should be able to see the edge of the drywall and, depending on how tight the jamb is to the wall framing, the jack studs that surround the door. Measure the width and height of the rough-in opening. I would also measure the thickness of the wall: while a 2x4 wall is fairly standard, you may encounter "sideways stud" walls that are thinner, or even a 2x3 wall. This could be the case in older construction near closet doors (my house has a few like this).
When you talk to the person helping place the special order, it helps to have all of these measurements already done. "Hi, I have a door slab with dimensions X by Y, rough-in is A by B. I need a pre-hung door that will fit in this opening."
Do not underestimate the importance of measuring all of these things instead of going to the nearest big-box home improvement store and grabbing a door off the shelf that may or may not fit. Even little things like making sure the mortises for the hinge plates match (if buying only the door slab) will save you time and frustration later on.