Yes, a prenup or postnup can affect who gets the house in a divorce. These agreements are like just-in-case plans where you establish who gets what in a divorce.
In particular, if you agreed to sell the house and split the proceeds in your prenup, that’s how your property division will likely end. If you forgot to add a provision concerning the house division and can’t agree on it during a divorce, you must go to trial and let the judge decide.