In the wild, yes, beldum and magnemite (and diglett, for that matter) need fellow pokémon to evolve. This is largely because these pokémon don’t naturally gain enough energy on their own, but they can gather this energy by pooling their resources together. When tamed, though, trainers will usually develop their pokémon’s abilities, which in turn allows them to develop the energy reserves needed to evolve on their own. Thus, these pokémon essentially undergo a form of budding that allows them to create clones of themselves in order to evolve. This may sound disturbing, but because evolution is often spontaneous, most trainers are fortunate enough not to see this process happening.
Slowpoke undergoes a similar transformation, by the way. The only difference is that in the wild, they simply force innocent shellder to merge with them, rather than members of their own species. Slowpoke are, truth be told, extremely terrifying once one gets past their slowness and innocuous appearances.