Different kinds of glues work in different ways, but there are some basic ideas that glue most of them together!
Have you ever thought about the different surfaces that hold together well with glue? While most of them might seem perfectly flat (like paper or Popsicle sticks), most of them actually contain lots and lots of tiny ridges and bumps on their surface that are too small for you to see without a microscope. When you apply glue to a surface like this, it fills in all of those nooks and crannies and uses that to grab hold of the object!
The glue is then made to change from a fluid (liquid-like) substance into a more solid one as it dries. For this to happen many glues they simply have to be exposed to air. Once the glue is dry, it works like a solid, hard bond grabbing hold of the object on either side that it’s keeping together!