CBD and Delta 8 THC were made legal by H.R. 2: The Agricultural Improvement Act of 2018, commonly referred to as the 2018 Farm Bill. They were specifically made legal in the bill where it states that hemp and all derivatives, isomers, and cannabinoids of hemp plant except Delta 9 THC are legal.
Up until to that point, CBD and Delta 8 had been illegal and were specifically named in the Controlled Substances Act. However, in addition to making all hemp cannabinoids, isomers, and derivatives legal, H.R. 2 specifically includes text to remove all confusion between laws by amending the Controlled Substances Act to exclude CBD and Delta 8 THC from hemp.
CBD and Delta 8 THC are federally legal and legal in Maryland. There are however some states that specifically exclude Delta 8 or have laws that do not specifically make all cannabinoids, isomers, and derivatives of hemp legal, creating a grey area for that particular compound.