Why ? to store colours as compact as possible; ppu only has 2kb internal nametable ram.
How ? Well, the docs describe it very well, but maybe an example would help:
Visualise Super Mario Bros, you can see that the world is built with many blocks sized 2x2 tiles (16x16 pixels). Each block is using 2 bits out of the attribute table. Take 4 of those blocks and form a square; 4x4 tiles, and you've got an attribute table byte.
Visualise the top left corner of SMB, comprising 4 typical SMB blocks:
block a, block b
block c, block d
Block a gets its high 2 bits for the palette colour at bits 0 and 1 of the attribute table byte. Block b from bits 2 and 3, block c from bits 4 and 5, block d from bits 6 and 7.
Now 1 step further: tiles, from the same space:
tile 1, tile 2, tile 3, tile 4, (5,6,7,8,9,10,etc)
tile 33, tile 34, tile 35, tile 36, (...)
tile 65, tile 66, tile 67, tile 68, (...)
tile 97, tile 98, tile 99, tile 100, (...)
Tile 1,2,33,34 get their high 2 bits for the palette colour at bits 0 and 1 of the attribute table byte, tile 3,4,35,36 get theirs at bits 2 and 3, etc.
This specific attribute table byte is located at name_table_start+0x3c0 (ntstart=0x2000, 0x2400, 0x2800 or 0x2c00).
*edit* can you boot games yet ? what i mean is running the cpu for a few frames without it calling bad opcodes
*edit2* typo