A court in Spain sentenced four men on Wednesday to jail terms of 10 to 24 years for beating to death a young gay man, in a case that sparked nationwide protests.