Why does the bitcoin mining code have the same if statement twice?
This is double-checked locking, which is


  ...a software design pattern used to reduce the overhead of acquiring a lock by first testing the locking criterion [...] without actually acquiring the lock.


This pattern can be fraught with issues; even folks who otherwise know what they're doing can be bitten by subtle issues.  See, for example, C++ and the Perils of Double-Checked Locking by Scott Meyers and Andrei Alexandrescu.

The particular use case you cite looks fairly innocuous, though.