When the federal reserve buys bonds or other assets from banks, do the banks make a profit? My understanding is that the federal reserve is injecting money in the market by buying bonds and debt from banks.   Do the banks make a profit on the sale of their bonds or corporate debt to the feds?  If not, what is their motivation for selling bonds or debt to the feds?
I am not sure about this, but the Fed mainly trades with Primary Dealers. These are often subsidiaries of banks, but could be independent financial entities. 


If the dealer is selling from its own inventory, it will make a gain or a loss depending on the price it originally bought the bond at. Since that may be some time ago, there is no certainty about profits.
The dealer may effectively act as an intermediary. It will buy from clients who are bond investors, and then sell to the Fed. If the trading desk of the primary dealer does a good job, they have a good chance of locking in a small profit. (Making recurring small profits by intermediating trades is the business model of investment dealers.)