How does aviation deal with satellite and Moon laser ranging, and other scientific lasers in the sky?
Is there a NOTAM or a temporary flight restriction associated with laser ranging activity?

Apparently yes:

The lasers on the telescopes are in the range of 15-40 watts. The FAA calls a no-fly zone over the area when a laser is in use, and two people have to stand around outside in the freezing temperatures and watch for airplanes. Each of them has a kill switch to turn off the laser in case an airplane comes near. [...]
To clarify, the FAA does not have a no-fly zone, but instead issues a “Notice to Airmen” or NOTAM about the laser operations.

I also worked on an Adaptive Optics project and it was given for granted that NOTAMs would be issued by the people in charge of the experiments.
Example of NOTAM:

FDC 0/7651 ZDC .. SPECIAL NOTICE .. LASER OPERATIONS EFFECTIVE
1005010001 UTC UNTIL 1112312359 UTC. SCIENTIFIC AND RESEARCH LASER
OPERATIONS WILL BE CONDUCTED AT THE NASA GODDARD SPACE CENTER IN
GREENBELT, MARYLAND, LOCATED AT 390113N/764939W. THE SYSTEM IS
INTERMITTENT, WITH POSSIBLE OPERATIONS HAPPENING 24 HOURS A DAY, 7
DAYS A WEEK. THE LASER BEAM MAY BE INJURIOUS TO PILOTS/AIRCREWS AND
PASSENGERS EYES FOR A DISTANCE OF 98,000 FEET ABOVE GROUND LEVEL.
HOWEVER, THIS SYSTEM USES A LASER HAZARD REDUCTION SYSTEM RADAR THAT
IS SLAVED TO THE TELESCOPE MOUNT TO ENSURE THE LASER IS DEACTIVATED IN
THE EVENT AN AIRCRAFT APPROACHES. THE AREA WILL ALSO BE MONITORED BY
OBSERVERS AND THE LASER BEAM WILL BE TERMINATED IF NONPARTICIPATING
AIRCRAFT ARE DETECTED. LASER IRRADIANCE LEVELS WILL NOT EXCEED THE
MAXIMUM PERMISSIBLE EXPOSURE LEVELS WITHIN THE LASER FREE, CRITICAL
FLIGHT, AND SENSITIVE FLIGHT ZONES. OTHER VISUAL EFFECTS, E.G.,
FLASHBLINDNESS, AFTER IMAGE, GLARE, AND DISTRACTION MAY OCCUR AT
GREATER DISTANCES. THE POTOMAC TRACON /PCT/ PHONE NUMBER 540-349-7541
IS THE FAA COORDINATION FACILITY.



How dangerous is a laser beam for passengers and crew, and for the aircraft?

For the aircraft (meaning the hull) it is no danger, 40 watts of unfocused power (astronomers do not need laser beams in the sky as focused as the beams in an optics lab) do not affect the hull.
For the eyes of pilots and passengers it can instead be extremely dangerous, see Why is laser illumation of a cockpit an emergency?