Assuming the clips on the key cap are not damaged and the nubs on the scissor mechanism are not broken, then you should be able to reinstall the key cap. Make sure the scissor mechanism is properly installed and moving properly. The scissor mechanism only fits together one way.
The bottom of the key cap has two clips on one side and on the other side there are two items where the nubs of the scissor mechanism slide into it first, then you press the other end of the key cap to snap the snap clips onto the scissor mechanism. If done incorrectly, the snap clips and/or the nubs on the scissor mechanism will break. If this happens, then you will need to source replacement parts which can be difficult since Apple typically uses two different manufacturers for the keyboards so they may end up using different scissor mechanisms & key caps. Plus each region has their own style of key caps.
You may find some guides on iFixIt, but keep in mind what I mentioned here since those guides may be for a very specific model or one with a particular style of key cap & scissor mechanism which may operate slightly differently than your keyboard (some scissors & key caps are very hard to distinguish even for an experienced tech).
Apple does have a Key Cap replacement kit and a Scissor Mechanism replacement kit available for AASPs which contains key caps & scissors for the entire keyboard so you will likely need to pay for even the ones you don't need. There is a chance you may be able to use Apple Self Repair Program to get these parts if yours are damaged depending if your exact model laptop qualifies for the Self Repair Program & the program is available in your region. Of course Apple would provide instructions as well.
Here is an Apple article where Apple provides some service manuals for the MBPro 14" M3 (it does contain a section regarding the key caps):
MacBook Pro (14-inch, M3, Nov 2023) Manuals and Downloads - Apple Support
FYI, you need to identify the exact model of your Mac. You can get this information by clicking the Apple menu and selecting "About This Mac". If the Mac is unable to boot, then you can get this information by entering the system serial number on the check coverage page here:
Check Your Service and Support Coverage - Apple Support
For the M3 laptops, you must also make sure to distinguish between the base M3 CPU and the higher end M3 Pro CPU and the M3 Mac CPUs.