Why go through with all the hassle of combining two slim boards, and not just purchase and use a thicker 2x4?
Cost
Wood of smaller dimensions can be cheaper, cheap enough that two smaller pieces can be cheaper than the one thicker piece. This is one of the prime motivations to do laminations and glue-ups.
In wood sales generally wider material is sold at a premium, and as a result some older guides specifically caution new woodworkers that while it might seem economical to buy a large board and cut it into all the smaller pieces needed for a project it can be much cheaper to buy a number of narrower boards instead, sometimes even if you end up actually purchasing more wood.
Note that you may choose to buy a wider board deliberately however, so the wood throughout a piece matches as well as possible in grain and/or colour.
Just one of many examples, Steve Ramsey can be seen 40 seconds into this video gluing together the faces of two 1x4 for the legs of a table
Now in this case there are some additional possible advantages.
Strength or stability
The first is strength, a glued-up 2x4 made from bonding together two 1x4s face to face will often be stronger and more stable than a sawn 2x4 of the same species. This won't always be the case, and the added strength may not actually be needed, but in the case of plain-sawn wood it can be quite a bit less prone to warping.
Simplifying construction
Another advantage is one of time. Although the glue-up is an extra step, if the leg is intended to have one or more mortises cut into it these can be formed faster (particularly with power tools) by sawing or routing away material prior to glueing the pieces together. Although it's not uncommon I couldn't find a photograph clearly showing this type of construction so I modified a diagram from a workbench build that uses a similar method so you can more easily visualise what I'm talking about:
In the above example the mortise is cut from just one of the two parts of the legs because they're of unequal thickness but with a leg made from two pieces of the same stock it's normal to cut two shallower channels on each half of the leg that combine to form the finished mortise width.
Decorative effect
In finer woodworking you may want to glue up a table leg rather than relying on a solid piece in order to get a particular run of grain running on all visible sides. A good example is if you want quarter-sawn grain on all four sides of a leg, something not found in nature:
Image from stuswoodworks.com
Although such a leg can be created more simply by using veneers it is often made by glueing together four pieces of roughly triangular section: