In general, 5 hours should be more than enough.
While queuing times and processing times vary, based on:
- The date and time of day
- The type of passport you have (especially if you require a visa or not)
- The type of visa
- Whether this is your first visit
- ...
I would expect immigration formalities to take less than one hour in a majority of cases, maybe 2 on a busy day (most of that is just queuing).
Of course, there can be cases where even 5 hours aren't enough:
- Your flight is very, very late
- You miss your connection in Dubai and are rebooked on a later flight
- Your flight is cancelled and you are rebooked on a later flight
- The UK Border Force have one of their meltdowns (usually an IT problem). They had plenty of those these past few years but they seem to have resolved issues (at least I don't think it has made the news recently).
- There are issues with your paperwork and you have to go into secondary and it takes a lot of time to sort out
...
Note that in some of those cases you may even be rebooked on a flight to LHR rather than Gatwick.
So while there's no guarantee that you will make that bus, it remains very, very likely that you will (I don't know which bus it is and how often it runs, but it's probable that you could even use an earlier one in most cases).