Assuming that on some equities buy/sell price spread become more than x% in order books, which let's assume is more than exchange fees, does it make sense to to buy/sell and earn money on spread? Does this trading algorithm have some name?
You won't earn money trading on the spread, you will lose money.
For there to be a transaction the bid and ask price will need to match.
So to buy you need to match the lowest ask price, and to sell you will need to match the highest bid price. The larger the spread the more you will lose.
Usually if there is a large spread there will be no transactions for long periods, this is called an illiquid stock. If you place a bid at the highest bid price you probably won't get a sale, you would have to match the lowest ask price to get a sale.
You should avoid trading illiquid stocks (stocks with large spreads), because you will lose money trying to buy in and lose more money trying to sell out.
Yes, this trading algorithm is called market making or more generally providing liquidity. In principle, the apparently free money is compensation for helping the markets to be liquid. The more people do this, the tighter the spread will be and the greater liquidity will be available on each side. In practice, the costs and risks associated with doing this keep all but the most efficient participants from making money this way.
This is essentially what designated market makers have historically done. True market makers always have a price at which they will sell and buy. They make money by selling at the ask and buying at the bid. But even if you don't always have a bid and an ask and you seek to make money on the spread, you are making the market.
Of course, market makers must have significant capital available, which costs something. In addition, they bear the risk that price changes will happen while they have a position that loses money. And of course they pay the various fees. Historically this role was filled by specialists or broker/dealers, who had a size advantage. Today it is just as likely to be filled by high frequency traders, who additionally have an execution and possibly informational advantage.
To be clear, market making involves submitting limit orders. If you are thinking of submitting market orders, then instead of making the market, you will decrease liquidity and lose money by crossing the spread.
The more liquid the stock, the narrower the spread and the more likely that price will move against you even if you get a good fill. The more illiquid the stock, the wider the spread is likely to be but the less likely that anyone will be willing to transact at those prices.
The exception to this is a fast market. The best example that I can think of was in 2008 and 2009 when I was trading preferred stocks issued by banks which were getting hammered. At times, I was the best bid and the best ask (by a penny) and was getting hit on both sides, sometimes within minutes. Panic can cause normal rules and behavior to disappear. In such a market, it's a time consuming effort because you have to set price alerts and every time that someone comes in at a penny better than you, you have to change your order and reset your price alert. It's well worth it in that kind of market but all of the rest of the time, it's a waste of time.