As far as I understand companies will take out loans against their own stocks in good times as they expect their stocks to generally go up and to make more money than the payments on the interest of those loans. If their stocks go down they need to make up the shortfall elsewhere. The loans are generally used to keep business operations running smoothly irrespective of actual business cashflow (for example some businesses make most of their profits at certain times of the year). I'm not saying this for sure applies to Elastic but I believe its a pretty common pattern across major businesses.
dont know the laws well enough, but would be crazy indeed if companies could borrow against their own stock when they're issuing first new ones with sbc and then buy back on open market.