The men were found guilty of violating strict Islamic laws in conservative Aceh and will receive 85 lashes each.
The pair, aged 20 and 23, were found in bed together by vigilantes in March. They have not been identified.
Gay sex is not illegal in the rest of Muslim-majority Indonesia and this is its first such conviction. Aceh is the only province where Sharia is in force.
The sentence is due to be carried out next week.
Eight convicted drug smugglers have been executed by firing squad in Indonesia.
Amnesty International described the executions as “utterly reprehensible”.
“The execution of eight people in Indonesia today shows complete disregard for due process and human rights safeguards,” it said in a statement.