I guess I'd say the difference between "sweet" and "malty" is the presence of mellanoidins which are formed by rather complex chemistry involving sugars, amino acids and heat. There are thousands of these and the source materials and treatment of them have a great effect on the nature of the result. If you look at light beers, they are usually neither malty nor sweet i.e. there may be some residual sweetness in them but not much. As you move to slightly darker beers, such as real Pilsner, the maltiness begins to become more noticeable. These beers are often decocted (which generates Maillard products), boiled for 2 hrs or more and often include some portion of caramel malt (which already has appreciable Maillard content). A twist with these beers is sometimes the presence of diacetyl which synnergizes with the sugars and Maillard products to produce (at low levels ) caramel flavors. How do you make caramel (the candy)? Heat sugar with butter (which contains diacetyl).
Moving to still darker beers you get more and more maltiness culminating with bocks and dopple bocks. These are malty for all the same reasons as the Pilsner example but also contain higher kilned (more mellanoidins) malts such as special B, Munich II, Munich I in higher proportion. Strong ales and Barley wines of course have at least roughly similar proportions of higher kilned grains but are not decocted and the esters and high hopping tend to distract the drinker from the maltiness.