It seems to me that the problem is indeterministic which probably means I'm missing something. At the very least, it's too loosely worded.
If 50% of the peasants get to heaven and peasants can only count to 5, that means that the numbers is in the set $[1-5]$ 50% of the time and in the set $[6-32]$ 50% of the time.
Peasants will guess all the numbers in the set $[1-5]$ in some order.
As suggested in the comments, a machine is likely to use a dichotomic search. That means they're going to start with the midpoint ($16$) and keep choosing the next midpoint based on whether the devil says the answer is higher or lower. In practice, that would look like this:
First: 16
Second: 8 24
Third: 4 12 20 28
Fourth: 2 6 10 14 18 22 26 30
Fifth: 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31
Note that $32$ is never chosen by the robot. It would need a 6th guess to get that one. (It would know the answer by the 5th guess ($\log_232=5$) but it wouldn't have an opportunity to actually say it.) For any other number, the robot is guaranteed to get it by the 5th guess. Since only 50% of the robots get it right, that means that $32$ is the answer 50% of the time.
Now comes the problem: We know the answer is $32$ 50% of the time and we know the answer is somewhere in $[1-5]$ the other 50%. However, the devil could have chosen any combination of $1, 2, 3, 4, 5$ so long as the total count was 500. That means the final answer is anywhere from $33$ to $47$.
Caveat: If we assume that all the peasants actually counted $1-5$ in order, then that means that the devil picked all those numbers with equal probability. This possibility is implied in the question but not explicitly stated.
In that case, the final answer can be determined to be $47$.