Garlic has a different chemical in it (allicin), but it hits the same receptors as capsaicin. If you've ever tasted a chimichurri with a ton of raw garlic before it's had a chance to mellow out in the oil, you'll attest that garlic can indeed be spicy.
Here are the main chemicals that are usually described as spicy - they all use the same mechanism to create a "heat" sensation, with the exception of the Sichuan peppercorns:
- Chile Peppers: Capsaicin
- Onions/Garlic: Allicin and Pyruvic Acid
- Ginger: Gingerol
- Black Pepper: Piperine
- Mustard/Horseradish/Wasabi: Allyl Isothiocyanate
- Sichuan Peppercorn: Hydroxy-Alpha-Sanshool
[1] https://www.nbcnews.com/id/wbna8963709