In the first example a = "aaba" splits into a1 = "aa" and a2 = "ba", while b = "abaa" splits into b1 = "ab" and b2 = "aa". The piece a2 = "ba" splits into "b" and "a", and b1 = "ab" splits into "a" and "b", so the second case of condition 2 makes a2 and b1 equivalent. The pieces a1 = "aa" and b2 = "aa" are exactly the same, so the second case of condition 2 applies again and a and b are equivalent.
In the second example a = "aabb" splits into a1 = "aa" and a2 = "bb". Each piece uses a single letter, so the only strings equivalent to a are "aabb" and "bbaa".