Bacterial cell walls and capsules are indeed two very different things, with unique compositions and functions:
Bacterial Cell Wall:
-found in all gram-positive and gram-negative bacteria (but slightly different in each)
-composition: a thick layer of peptidoglycan found outside of the cell membrane (in gram-positives) or a thin layer of peptidoglycan found between the inner and outer cell membranes (in gram-negatives) *remember that gram-positives do not have an outer cell membrane
-function: to maintain the integrity of the cell (it holds everything together, but doesn't really 'protect' the cell per se)
Bacterial Capsule:
-found in some gram-positive and gram-negative bacteria (but not all)
-composition: a dense layer of polysaccharides, NOT peptidoglycan, found outside of the cell envelope (some capsules contain amino acids, like in B. anthracis, but this is the exception, rather than the rule)
-function: to protect the cell; capsules can protect the cell from desiccation, and can prevent the bacteria from being recognized and 'eaten' by host immune system cells like macrophages; capsules can also help bacteria to adhere to surfaces by forming biofilms
Hope this helps!