The index is a B+ tree. That means that under the by_id 1 there are all records with posted_on 0 and by_id 1, and then you have all the ids for those records. Under the by_id 7 however you have another tree branch, that contains records with posted_on 0 and they contains the records with their ids.
When you have in clause, you are retrieving 3 different branches of the tree, you have to merge them and resort them, since ids with 1,2,4 may be under by_id 1, but 3,5 under by_id 10; MySQL retrieves 1,2,4,3,5 and have to resort them.
In the first case there is only one branch, and each branch is already sorted