Hundreds of millions of dollars meant to provide a little relief to the nation’s struggling homeowners is being diverted to plug state budget gaps. In a budget proposed this week, California joined more than a dozen states that want to help close gaping shortfalls using money paid by the nation’s biggest banks and earmarked for foreclosure prevention, investigations of financial fraud and blunting the ill effects of the housing crisis. California was awarded more than $400 million from the banks, and Gov. Jerry Brown has proposed using the bulk of that sum to pay the state’s debts. The settlement, reached in February after a year of talks and intervention by the Obama administration, was the second-largest in history involving the states, trailing the tobacco industry settlement, and represented the first large-scale commitment by banks to provide direct aid to borrowers. Only 27 states have devoted all their funds from the banks to housing programs, according to a report by Enterprise Community Partners, a national affordable housing group. So far about 15 states have said they will use all or most of the money for other purposes.