I've looked into this before, since I am looking to do my own headlight retrofit. The options going down are cheaper, but are riskier and require more DIY/effort.
If you decide on OEM or Aftermarket assemblies, you will need to determine if you have directional/adaptive beam or not; I believe this is when the headlight turns with the steering wheel.
OEM
Mazda only sells the headlight as an assembly.
The part numbers are as follows for the Left, there is one with and one without directional beam:
KL2J-51-041C
	
	
		
			
			
				
				2017-2021 Mazda CX-5 Headlamp Assembly KL2J-51-041D
				
					
						
							 
						
					
					www.mazdabestpartsonline.com
				
 
			 
		 
	 
KL2L-51-041C
	
	
		
			
			
				
				2017-2020 Mazda CX-5 Composite Headlamp KL2L-51-041C
				
					
						
							 
						
					
					www.mazdabestpartsonline.com
				
 
			 
		 
	 
Purchasing new is your best bet to have peace of mind of a perfectly working new OEM unit. I would ask your nearby Mazda dealer's if you can purchase and pickup that part number from them. In my experience, some dealers do not want to let you do this and you may have to search online for Mazda Dealers Parts websites to see who has the best price including shipping. The dealer I linked above in my experience has the cheapest parts including shipping.
Another option is to search for the part number on eBay and see if there are good deals on used assemblies and sometimes there are Mazda dealers selling on there as well. Also check junkyards, other websites selling OEM, etc.
Aftermarket
Another option is to purchase aftermarket or remanufactured headlight assemblies. I am personally not a huge fan of these. In my experience, the quality is just poor. Examples:
	
	
		
			
				
			
			
				
				If you’re in need of replacements for your 2019 Mazda CX-5, our selection of custom & factory headlights includes projector beams, LEDs, Halos and more.
				
					
						
							 
						
					
					www.carid.com
				
 
			 
		 
	 
	
	
		
			
			
				
				
				
					
						
							 
						
					
					www.protuninglab.com
				
 
			 
		 
	 
	
DIY
The final option is to purchase an aftermarket headlight lens from China. At ~$65 this is the cheapest and riskiest option, as you have to hope it fits perfectly, is shipped to you in one piece, and you will have to wait at least a month for shipping from China.
	
	
		
			
				
			
			
				
				Smarter Shopping, Better Living! Aliexpress.com
				
					
						
							 
						
					
					www.aliexpress.com
				
 
			 
		 
	 
	
	
		
			
				
			
			
				
				Smarter Shopping, Better Living! Aliexpress.com
				
					
						
							 
						
					
					www.aliexpress.com
				
 
			 
		 
	 
You will have to heat up your current headlight assembly, remove the lens, remove the old adhesive, add new adhesive, and attach the lens back. You can look up these videos on YouTube where people do headlight retrofits where they remove the lens and put it back.
Notes
In conclusion, if you need an assembly now, definitely go through a Mazda dealer to get the whole assembly. You can save a little money by finding a used unit. You can save the most money by going down the DIY route by purchasing from China. The choice is yours.
As mentioned, you will have to drop the front bumper. And when you are done, you may have to re-aim your headlights.
Let me know if you need more information on anything.