Gay people travel to Tanzania and they are also booked in the same room, as well as a shared bed. Tour operators are quite aware and it is worth understanding that there are numerous countries where homosexuality is illegal; Tanzania being just one of several in East Africa.
It’s important to note that public displays of affection are not well accepted even between straight couples, so decorum is just smart practice here for all visitors. Imagine watching a mother and son greet each other on the street – no hugs, a hand shake, that’s all. This is as far as it goes, although it is customary for men to hold hands (this is not unusual). Guides know tourists are a little more affectionate, and may give you a hug, but it would only be done in a tourist setting. Despite Zanzibar’s colour and hints of exotic, it will not be any more lenient than mainland Tanzania.