One way is that you don't give the source code, but only sell software and after-sales service. After the software is sold, if you need to modify the function, you can modify the software for them at a suitable price, or don't give the source code.
If your software has good economic benefits, you can also consider applying for a software copyright. Although you have copyright after the software is written, it will be more convenient and cheaper to defend your rights if you have a certificate.