BANDA ACEH, Indonesia—Two men were lashed with a cane as punishment for having same-sex relations, part of a growing intolerance of sexual minorities that has marked the rise of more conservative Islam in the world’s largest Muslim-majority country.

The flogging Tuesday marked the first time the cane has been used to punish same-sex relations in the province of Aceh, though it is used for other offenses there. Besides the two men, eight other offenders were whipped alongside the two, including a heterosexual couple punished...