LONDON — The British oil giant BP said on Tuesday that it lost $5.8 billion in the second quarter, reflecting a huge settlement over the 2010 Gulf of Mexico oil spill.