As the comments on the OP mention, similar questions have already been answered on academia.SE. Having read those, and speaking as a mathematician, I think our culture is a bit different regarding affiliations. In my experience, mathematicians have broad leeway to choose whether to use their former place or current place, and neither option is "right" or "wrong." We also have a culture of acknowledgments in papers, where people list their funding sources, who gave them helpful tips about the research, and which places hosted them as they wrote it. It's common for early career researchers to publish results from their PhD theses, but with their affiliation as the university where they are employed as a postdoc or assistant professor. In these cases, usually there's a line in the Acknowledgments section like "These results were prove as part of my PhD thesis at University X, and I want to thank my advisor Y for their help over the years."
The most important thing about the affiliation is having a stable email address where people can reach you. If there's any concern at all that your old employer won't maintain your email address with them, then don't use it. Similarly, while the odds of actually receiving postal mail regarding the publication are slim, it's best to have an address where that would actually reach you. I have a co-author who moves jobs frequently, and every time he does, we update our preprints to list his new affiliation, even though it's not where he was when the paper was written.
Similar advice can be found in fedja's answer on academia.SE.