You can make a TAS and that will give you an approximate theoretical time.
In some cases, games are simple and/or well-defined enough that you can relatively easily calculate the fastest possible time, if there are always a specific number of possible paths you can take at any given time so you can just find the fastest one. In some cases you can go even further than that, such as with Dragster where people managed to find/recreate the source code, and it was short enough that someone did an analysis of literally every possible outcome from every possible series of inputs, and found that the theoretically fastest time possible was 5.57 seconds.
Segmented runs are also a good way to find out what's theoretically possible. By eitehr taking IL's from the community or grinding and stitching together hundreds of segments, you can get an idea of what the fastest possible time would be, with perfect movement and no mistakes.