Sugar and salt when kept in different jars do not gain their shape or the shape of the sugar or salt crystals do not change at all. This happens because of very small size of crystals, when they're put in a container, they fill it and some small spaces are left which are not very noticeable and that is why we tend to think that sugar/salt take up the shape of their containers.
For example- if we put dry fruits (say almond) in a container. They also remain in shape, same as in the case of salt or sugar.But just because they are larger in size, spaces in between them can be noticed. And that is why we say that almond doesn't gain the shape of container - because spaces are noticeable.