Mechanical keyboards are not necessarily better than membrane keyboards. They are, however, different in terms of features and functionality. Mechanical keyboards have a unique set of features that works for specific purposes.
A membrane keyboard has its name because of its layers. The keyboard has a top membrane layer, followed by a middle layer and another membrane layer at the bottom. The whole keyboard shares the same layer instead of the mechanical keyboard, which has its separate keys with each part set up.