Both boy and girl dogs can engage in this behaviour and it is not always the way we see it.
It can be a play behaviour and is seen in puppies as well as teens and adults, it can be a dominance related activity although that is not always the case and it can develop into an attention seeking behaviour.If the animals in question are both neutered and it does not provoke an aggressive response then distraction is your best policy when in public - the ball ( tennis ball - no pun intended - honest!) or a game or just run away very quickly calling both dogs in a happy, cheery voice. If it occurs in the house and in private be very careful how you react - making physical contact can encourage this behaviour - your best plan is to pretend you just don't notice and walk away - the dogs will sort it out and it isn't anywhere near as much of an issue for them as it can be for you. A male dog will not understand that he is being deprived of sexual behaviour when he is neutered and will not engage in this behaviour because he feels deprived - it is well documented, however that male dogs that have had previous mating experience before neutering often continue the behaviour - this is one of the reason it is a good idea to have a male dog neutered before he has a mating. With a rescue or waif and stray animal you may not be aware of the history. If you simply distract the animal when in public without making an issue of the activity and ignore it when at home - make a point of walking away from the dogs when this behaviour begins - it should decrease fairly rapidly.

I have just read the other posts here - castration in this country usually involves removal of the testes - if castration involves the cutting of the Vas Deferens only (the tubes) then hormone levels will remain unchanged and entire male behaviour should be expected.