Microsoft violated the license they had signed with Sun
But, but, you said you can't license an API?
If there were no copyrights in APIs, Microsoft could have made their incompatible version without a licence, incompatible or otherwise. They just couldn't have called it Java. That would be a trademark issue.
APIs are not just a method or procedure. Read the judgements on appeal in this case. Oracle has prevailed on the legal question that their Java API code was copyrightable. Google is continuing this fight on the question of fair-use, although the second appeal denied them this defence.