US flags on federal property are lowered to half staff at the discretion of the President of the United States. State flags on state property are lowered to half staff at the discretion of the Governor. From the United States Code, Title 4:
By order of the President, the flag shall be flown at half-staff upon the death of principal figures of the United States Government and the Governor of a State, territory, or possession, as a mark of respect to their memory. In the event of the death of other officials or foreign dignitaries, the flag is to be displayed at half-staff according to Presidential instructions or orders, or in accordance with recognized customs or practices not inconsistent with law. In the event of the death of a present or former official of the government of any State, territory, or possession of the United States or the death of a member of the Armed Forces from any State, territory, or possession who dies while serving on active duty, the Governor of that State, territory, or possession may proclaim that the National flag shall be flown at half-staff,
The American flag on federal property can only be lowered when the president or governor has ordered it to be lowered. Similarly on United States Post Office locations, federal prisons, ect.