Wash them right before you use them. You could wash them when you get home, it's not going to hurt most things if you're gentle, but that won't mean they're still clean once you're ready to use them. I'm guessing you aren't storing them somewhere sterile, so they will get dirty again during storage, and you'll just have to wash them again.
The other issue with washing a considerable amount of time before using is that washing doesn't remove 100% of bacteria on a surface. It should get rid of enough so it doesn't make you sick, but if you let it sit long enough after washing, the bacteria could reproduce into a dangerous quantity again. Obviously that's not true of everything you wash off produce (it's not going to magically gain more pesticides and some pathogens can't reproduce on the surface of produce), but it could be of some things.
In short, washing produce when you get it home isn't sufficient to make it safe to consume later, and you probably don't want to wash it twice if you don't have to, so just wash it before you use it. An exception might be in the current pandemic situation, where you want to get rid of any viruses on your produce before putting it away. In that case, feel free to wash produce when you get it home along with other washable items, but you should still wash it again before using it.
With that said, nothing makes eating raw produce perfectly safe, so it's really a matter of your risk appetite. If it's much more convenient for you to prep your produce in advance and you keep them in something that's thoroughly washed between uses, then it's not terribly likely to hurt you. It's a bit safer to wash them closer to when you use them, and some things may keep longer if they aren't washed, but it wouldn't be unreasonable to wash them sooner in some cases.