Epoxy Resin Molded vs Hermetically Sealed Metal Can Packaging for LEDs and Photodiodes
The main purpose of the metal housing is to secure a lens used for directing light into the photodiode or out of the "point source" LED, as well as block light from entering or leaving in the wrong direction. Those devices are used mainly for optical sensing and instrumentation applications due to their narrow radiation pattern.

The metal housing could be a good heat dissipator. But considering those devices are orders of magnitude more expensive than their non-canned version, I'm pretty sure a good designer would look for better and cheaper ways of keeping the device cool.