It is likely that your sensor is reporting inf when it cannot see an obstacle. inf values are filtered out to avoid inaccuracies in the sensor. You are correct with the maxRange and maxUrange behaviour however if the sensor reports an inf then it cannot be handled by this condition. You could get around this by first setting any inf values to the maximum range of your sensor (prior to entering gmapping)