For federal tax purposes, you may file a joint return with your deceased spouse for the tax year of death if you were legally married at the time of death and you did not remarry before the end of that tax year. This is permitted under Internal Revenue Code §6013 and IRS guidance in Publication 501.
However, if you have remarried before the end of the tax year, you cannot file a joint return with your deceased spouse for that tax year. Your filing status for that year is determined based on your marital status on the last day of the tax year (December 31).
If you are remarried, you must generally file either Married Filing Jointly or Married Filing Separately with your current spouse, depending on your circumstances.
After the year of death, you may qualify for “Qualifying Surviving Spouse” filing status for up to two tax years following the year of death if you meet all IRS requirements, including not being remarried at the end of the tax year and having a qualifying dependent child. If you are remarried, you are not eligible for Qualifying Surviving Spouse status.
Source:
Publication 501
Disclaimer: Always verify your filing status and eligibility with the current IRS forms and instructions, or consult a tax professional for personalized advice.