The answer is quite simple. If you change the object you are working with, it will restructure automatically. What is happening is the following:
Your starting list -> [10, 5, -2, 23, 5, 6, 7]
Step 0. First iteration of the loop (checks the first element of the list) -> 10 <= 5 False
Step 1. Second iteration of the loop (checks the second item in the list) -> 5 <= 5 True
Your current list -> [10, -2, 23, 5, 6, 7]
Step 2. Third iteration of the loop (checks the third item in the list) -> 23 <= 5 False
As you can see, when you removed the number 5, the -2 became the second item in the list. However, the for loop does not know this, and it will continue to search with the next values thinking that it has already checked for -2, since it is now the second value in the list.
This is why it is not recommended to change objects while iterating with them.