Yes, this seems surprising at first. The difference here is that recognizing the first language requires unlimited memory. Indeed, to check whether is in the language, the automaton has to read all a's and remember their number, then read all b's and check that their number is the same as that of a's.
Recognizing the second language, on the other hand, does not require infinite memory because one cannot have a sequence of "ab" without also having "ba". Note that it is crucial that the alphabet does not contain other symbols besides a and b. Suppose there is a substring "ab". To have another "ab" further along, one must first encounter "ba". Therefore a counter that contains the number of "ab" minus the number of "ba" encountered so far cannot go above 1 or below -1. A finite automaton can track this and accept a word if the counter is 0 at the end.