Ultrasonic sensor doesn't work inside case
It is likely that the transducer and receiver are being coupled together by the enclosure, so that the signal being received first is the vibration through the enclosure rather than an external object. I would recommend enlarging the holes so they are not in physical contact with the enclosure.

You may also be getting similar problems if the board is secured very rigidly to the base of the enclosure, in that case maybe consider using some o-rings between the mounting hardware and the enclosure. But try step 1 first if the holes are tight fitting.