gmat scoring isnt a simple calculation of correct and incorrect answers, its adaptive. Pretty much, its trying to find your level, it'll ask you a question, and if you answer correctly, it will follow with something harder. If you answer incorrectly, it will ask something easier, and so on. The idea is, within 37 questions, it will gauge your level of knowledge.
In the first test, you started strong and slipped up a bit in the middle, but by that point you were answering questions at a higher level. So high, that even your slip ups in the second half didnt bring your score down further(the two correct at the end helped).
On the second test, you started off weakly, getting half of the first twelve wrong. You were able to rebound nicely in the middle of the test, but you werent able to keep up that level, and the test decided your level was a bit lower.
Now, this obviously isnt an exact science, and 800score may not have the algorithm down correctly, but to simply answer your question... your score was lower in the second test because the last problem on test 2 was considered to be at a lower level then the last question in test 1
This is in no way saying that the first half of a test is more or less important, every question is an opportunity to raise your level, it only matters where you end.