By dragging a dimension to the colour shelf, each category is assigned a colour. This allows the user to quickly distinguish between different categories.
Tableau assigns some default colours that you can then change in several ways. You can either click on the colours shelf and select “edit colours” or double click a colour on the legend, which will also bring up the colour editor. You can now select the colour palette drop down to get a list of predefined colour palettes. You can select a colour palette you would like to use and ask Tableau to “Assign Palette”. This will randomly assign colours from this palette to the categories. You can also change these out individually, if you are not completely happy with this random assignment.
If you want some more control over your colour scheme you can of course pick colours from different Palettes or you can simply double click the category colour in which will bring up the advanced colour selector. Here you can now create exactly the colour you want, either by moving around the cross on the colour overview, picking a colour from the screen or entering a colour hex code.