All sorts of options for situations exist, and are usually some sort of negotiation between the funding organizations and representatives of the universities involved (at least when we're talking about a faculty member moving-- postdocs have some other issues, which I'll get to eventually).
First, faculty members switch universities all the time, and try (usually successfully) to take their grants with them. The research contracts are almost always to the University, not to the investigators, who are just employees of the contract holders.
You might ask "why would a university awarded a research contract be willing to let it move to another university?" Well, there are a few reasons. The original holder, given that the key employee will no longer be there, may no longer be able to fulfill the contract without them. Also, sometimes faculty move out of a university, sometimes they move in. The receiving university will find that if they oppose letting grant money travel with exiting employees, that other universities will oppose grants moving to that receiving university. It may also tick off portfolio managers at the funding institutions.
Let's kick the complexity up a notch. Let's say Prof A, the primary grant holder, has a collaboration with Prof B at the same university on this hypothetical grant. What happens if Prof B moves? Well, lots of things can happen. If Prof B is done with their share of the research, simply removing prof B from subsequent years of the grant is certainly an option. If prof B is important, and the research needs to continue, the grant can often be modified such that the original uni cuts an annual check to the new uni to cover research expenditures under the grant. If Prof B's contributions are huge, the grant may need to be modified to convert some of the ongoing funds to more of a consortium arrangement. You find out what the funding institution wants to do by talking to them. Universities usually have staff capable of initiating these conversations with the funders.
the issues are similar if Prof A moves.
Now, what about postdoc funding. The devil here is all in the details, and depends heavily on the details of the grant. If the postdoc is simply an employee on a PI's grant, the PI may simply choose to hire a new postdoc, and cut out the original postdoc. This seems most like your case to me, but I can certainly be wrong. Would you be "key personnel" on the grant, or would you be a co-Investigator? If you're the former, chances are lower that the money would follow you.
If the grant is a development grant for the postdoc, the funding institution may well demand that the money follow the postdoc. There are probably dozens of other situations and in-betweens here, but without knowing more details, real answers are difficult.