That keyboard is one of the dreaded Butterfly keyboards where it only takes a bit of dirt to cause the keys to malfunction. Here is an Apple article on how to use a can of compressed air to clean the dirt from the keys, but make sure to read the instructions carefully:
How to clean the keyboard of your MacBook or MacBook Pro - Apple Support
Make sure to keep the can of compressed air completely upright or you risk permanent damage to the laptop if the cold wet propellant sprays from the can (only happens when the can is tilted).
If this does not fix the issue, then either there is too much dirt that cannot escape on its own, or maybe a bit of liquid has gotten beneath the key. An experienced tech can attempt to remove the key cap and clean it, but even an experienced tech can easily break the key since the spacebar is not an easy key cap to remove. Apple does have a free Keyboard repair program, but it is only available for up to 4 years after purchase of the laptop.