Thanks for asking your question! I'm sorry to hear about your tax issue and I'm going to try my best to help you understand or resolve it.
How are you today?
It is my opinion that you do not have to pay the capital gains tax, provided the tax is below $250,000
You would only be able to avoid tax on your $250,000 not the marital $500,000 because your wife did not live there and it was not her personal residence
The homestead exemption only deals with your real estate property taxes
For federal tax purposes, a home is your primary residence if you live in it for 2 out of the last 5 years