Well it does not exactly work that way, its true that Maya REQUIRES object names to be unique. But what maya consider to be the name and what you consider to be the name are 2 separate things.
To illustrate this to yourself do this:
make a new scene, make a object named "box" and a object named "ball". Try to make a new object named box... does not work right maya does not allow it makes box1. Now make a object named "nameTwoTimes" and move it under box, now make a new object with "nameTwoTimes", now Maya allows it. What the hell is going on? Well quite simply the real names of a objects are:
|box
|box|nameTwoTimes
|ball
|nameTwoTimes
See not a name 2 times just the shorthand name 2 times. Its analogous to how you can have a person with same name in class but with different surname, social signature etc. The first name of somebody is not the fully qualified identifier of somebody but it suffices in most cases, until it does not obviously.
Second:
you also have name spaces, name spaces allow for same name to be in the scene 2 times off course its not really 2 times in the scene, its just been hidden away form you unless you tell otherwise. All functions are blind to name spaces until explicitly told otherwise. One name space is active at a time. Situation is the same but the names would be something like.
|nameTwoTimes
otherNamespace: |nameTwoTimes
now unless you EXPLICITLY tell your editors to show name space you wont see any difference in name of objects. But this is just one of those things I allays stress to you guys. Do not equate "it works" with "it always works", which is why I in general advocate not to use mel syntax in expressions, or storing object names persistently. Doing the former is ASKING for problems like this, biggest reason being that "it works" but not always. Which is a catch that gets everybody eventually, so avoid it at all cost, if possible.