Specifics depend on the specific stimulator you were given. But the basic way they tend to work is by altering the balance of osteoblast and osteoclast function. Osteoblasts form bone and osteoclasts “eat” bone (so that it can be replaced). Stimulators can make osteoblasts more active or reduce the activity of osteoclasts so that more bone matrix is deposited than eaten.
The better question is “do they work?” Last I checked, the data for them is not very great, and they probably only work under specific circumstances. This is an excellent article about the topic, and not too old:
https://www.podiatrytoday.com/blogged/does-evidence-support-use-bone-growth-stimulators-after-common-podiatric-surgery-procedures
Latest Answers