Mileage can be stored in multiple modules but most of the time it's found primarily on the instrument cluster itself. Sometimes the data inside the instrument cluster can go corrupt and needs to be re-flashed in order to show properly again.
If the instrument cluster LCD (odometer display) isn't working at all or the cluster has power loss, then the mileage should show once those issues have been repaired. However, when there are weird values, an odometer showing 'ERROR', displaying all 999999s, or a value that isn't accurate; a mileage programming service will be required.
There are several ways to find the last known mileage once that happens. Other modules like the ECU/PCM (Engine Control Unit), and BCM (Body Control Module) might store that data however a good OBDII scan tool that can do advanced diagnostics might be required.
If all else fails, you can find the last known mileage from your last visit to the mechanic when you had your vehicle serviced. Mileage information is usually written down and can be used to approximate the closest last known mileage.