I changed my bathroom light switch for a Occupancy Sensor Switch but it would not turn off. Since the package said Ground Wire Required I figured it was a ground issue. The location has wiring from 1962 so I tested the switch in a newer location and it worked fine. Instead of connecting the Green Ground screw to the ground wires in the box I tied it in with the neutral wires and it works fine now. Its the only switch in the box and no other wires in there. Can I leave it like this or is it a hazard?
That's actually terrible. You bootlegged neutral and that is something you should not do anywhere.
It would have been much wiser to choose a switch that requires neutral since you do indeed have neutral in that box. I gather at the time you bought the switch, you didn't know that.
Most likely what is happening is the switch is a smart switch which requires neutral to power its internal electronics. And either a) this is cheap Cheese junk direct shipped from Shenzhen (possibly via an Amazon Fulfillment Center) that has never received a bona-fide UL listing and is not safe, or is one of the cases where UL authorized use of the ground to serve the part of neutral. The latter is done so the switch will work in locations that do have ground but don't have neutral. NFPA has told them to stop approving that.
So, ironically, you have done an unauthorized bootleg of an authorized bootleg, bringing it full circle, right back to manufacturer intent. So what's the problem? The problem is Neutral still is not Ground. If this neutral wire has a problem, it is a guarantee that the grounded parts of this switch (like the cover screws) will be energized at 120V. Now we hope the UL listing was predicated on the idea that the switch can't leak enough current to kill anyone. We hope.
My recommendation would be to remove this switch, reuse it somewhere else you have ground but not neutral (assuming it is not mail-order rubbish), and fit a "neutral required, ground not required" switch here.
Many electronic devices use the ground for a "handshake" or "acknowledge" ping. This is not the intent of the use of a grounding conductor per the NEC, but is used in electronic equipment since it they are not regulated and don't seem to care. Your situation is not uncommon. I can't say that what you are doing is 100% ok, but it does seem to make the sensor work. You might search out for another sensor that doesn't require a ground or install new wiring for that circuit at your earliest convenience.