Characterization of Sidon sets and Λp sets on compact groups