How about this. Iran are now struggling under the weight of US sanctions which are severely restricting their options to earn foreign exchange. They think well if the US are are making things tough for us let's show the the world we too can show our muscle and make things difficult for everyone else. Notice the ships were not sunk but just damaged which you can see from how the mines were placed. So why? Had they chosen the Iranians could have destroyed them just as easily, that may have been seen as a step too far. As it is they are saying to the US and the rest of the world, look we can make things difficult for you if you want to make things difficult for us. It's a game of brinkmanship and Trump has rightly stepped back from it. Maybe the Iranians think this gives them a bargain chip, what happens next is anybody's guess.