Hi, the workaround of using a static variable is ok but of course would not necessarily work well in any situation but I'm glad you got it working somehow .
However you're right, this is a known issue in NodeManager. https://github.com/mysensors/NodeManager/issues/176 should tell you why and answer your question #2. The solution unfortunately is not that easy since would require re-thinking the way sensors are mapped to child IDs. Work is in progress though (https://github.com/mysensors/NodeManager/issues/198)
@rakeshpai not your fault, it is just not easy to see When you register a sensor this could create one or more child IDs. How many, depends on the sensor. If you have a look at https://github.com/mysensors/NodeManager/blob/development/NodeManager.cpp#L3139 you can see for each sensor_type how many. As a rule of thumb, add 1 every time _getAvailableChildId() is called. If you need a summary table I can make it for you.
Defining MAX_SENSORS is not mandatory but since we may risk to have precious storage wasted, better to address this at the first run I think