Firm, short, direct boundaries. It can be done politely without explaining yourself. In fact, do it without explaining yourself. Explaining weakens your case.
Maybe something like, "please stop texting me." And repeat as necessary.
You can probably find some good videos or articles online about how to set boundaries effectively. It's very hard for a lot of us.
Good luck