Thanks for reaching out! There’s not a lot of literature on this specific question, but if you’ve recieved syphilis medication recently, masturbation (sexually pleasuring yourself) does not pose any re-infection risk. Masturbation is not an STI transmission risk when you are only touching your own body, so it is a very safe and normal way to experience sexual pleasure alone. Remember to wash your hands before and after masturbating (or accidentaly touching the area) and give any sores some time to heal before touching them directly, as this can cause pain or irritation.
Great to hear that you’ve already been tested and treated for syphilis. Your clinician may have asked you to return for a follow up appointment(s), where lab results may be able to determine if you have cleared this infection. You can also discuss with them how often STI testing might be right for you.
People who’ve been treated for syphilis are advised to abstain from sexual intercourse with other people for 7-10 days after their last dose of medication, and any time there is a sore present. While masturbation is safe, any contact between a partner’s body and a syphilis sore or rash is a common way to pass the infection.