IRS Publication 523 (2025) covers this case. You are a sole or joint owner. Your former spouse is allowed to occupy the home under a divorce or separation instrument. Your former spouse lives there as a principal residence. Then you treat the property as your own residence for the exclusion.
Publication 523 defines a divorce or separation instrument in three ways. It is (a) a decree of divorce or separate maintenance or a written instrument incident to it, (b) a written separation agreement, or (c) a decree requiring a spouse to make support or maintenance payments.
IRS Topic no. 701 sets the base tests. You exclude up to $250,000 of gain, or up to $500,000 if you file a joint return with your spouse. You must own the home at least 24 months of the last 5 years before the sale. You must use it as a residence at least 24 months of the previous 5 years. On a joint return, either spouse meets the ownership test and both meet the use test individually.
Maryland Family Law Article section 8-208(d) adds one point. An order granting sole possession does not affect the other party's right to claim the family home as a principal residence for tax purposes.
Next step: write down your move-out date, your purchase date, and the date of the instrument. Give all three dates to your CPA before you list.