Jim's answer already talks about laser classes, which are important to think about if your concern is the danger from laser pointers or their applications (rifle boresighting, rangefinders, red dots, &c). For any military, scientific, or commercial laser provided to you with its own inclosure though, it's almost always going to be a class 4 laser as it comes out of the tube.
Your specific question
Does a laser beam have to hit the eyes in order to damage them?
Or can a persons eyes get damaged by looking at a beam that goes past their eyes (e.g. looking at a laser beam moving inside an enclosure)?
is nonsensical as asked. Of course the laser beam has to hit the eye in order to damage it and a laser completely inclosed within its housing can never make contact with the eye or damage it in any way. If a laser is firing within a steel box, looking at the steel box isn't going to hurt your eyes at all unless the room is too bright or the steel starts to glow as an extrapowerful laser makes its way out.
Just as clearly, though, what you're trying to ask is how strong does a laser need to be to hurt you from its reflections. If you're looking at a laser as it works, most of its power is going straight down from the focus lens into the material but there's a nonzero amount of power being reflected from the surface to everything line of sight around it. If you're shooting a CO2 laser into something nonorganic and highly reflective like polished aluminum or some mirrors, there will be a large amount of power reflected.
I don't have enough credit on this stack to downvote Jim's answer, but it's misleading to the point of being wrong. What's dangerous is laser density at organic-affecting wavelengths, not just raw output power out of the gate. Case-Western Reserve University in Cleveland has a laser safety guide that covers most of the important points from the relevant American standard ANSI Z136. There are some minor differences between that and the EU standards IEC 825 & 60825, but ANSI itself has mostly adjusted its ideas to match Europe's and most differences in American labelling (labels talking about Class IIIb and Class IV instead of Class 3R and Class 4 eg) are down to the US government not having updated their implementation of ANSI's suggestions in 21 CFR 1040. (Paragraph d in Subsection 10 does have pretty thorough and freely available charts of the wavelengths, intensities, and durations that produce dangerous laser densities though.) In any case, infrared lasers above 500mW are labelled Class 4 because at that level of power they can cause severe eye damage within a fourth of a second, quickly enough that it's impractical to expect anyone to be able to react quickly enough to avoid damage. Similarly, Class 1 lasers are so harmless they can be viewed indefinitely long without any expected damage even if focused (eg through a microscope or telescope). Whatever power they have is incapable of harm or even when focused dissipates harmlessly in human tissue as a matter of course.
Class 2 and Class 3 lasers, however, aren't necessarily harmless if they are focused or viewed for extended periods of time, allowing the laser's density to build up on the exposed surface. Similarly, under current regulations, a Class 4 laser can be incorporated into a product that as a whole is considered Class 1 if its cover has an interlock switch that automatically cuts power when the case is open. Such "Class 1 laser systems" or "products" can still expose operators to Class 4 levels of damage if there's a viewing window in the cover that doesn't provide high enough optical density (OD) protection at the laser's wavelength. Even if the operator's window or own eyewear offer high OD protection at the correct wavelength, strong enough reflections from a Class 4 laser can still do damage over time as the transferred energy builds up into a small enough space on the cornea or retina. Follow the instruction manuals and warning signs, especially around commercial systems with a financial incentive to game certification requirements: ALWAYS wear suitably protective eyewear for the correct wavelength around strong lasers and NEVER stare at the active laser, even through protective covers and eyewear. (Yeah, you could theoretically do the testing for the exact levels of reflected IR light for your system and do the math about the energy density being transferred to your cornea and focused onto your retina... but better to just be nearby, check periodically if there's a fire or other problem, and otherwise look somewhere else while it does its thing.)