Since only those who are worthy are able to lift Mjolnir (as established in Avengers 1 and 2), why couldn't Thor or Captain America in Avengers: Endgame just put Mjolnir down on a part of Thanos (e.g. hand, foot, chest), preventing him from moving?
Thanos is never incapacitated long enough
During the fight with Captain America and Thor, Thanos is either on the attack or is never down long enough for Mjolnir to be placed anywhere.
Even when Captain America calls down lightning and floors Thanos for a second. At this point Cap attempts to (ahem) hammer Thanos by bringing Mjolnir down on his chest but Thanos just rolls out of the way.
Basically, you can't put Mjolnir down on someone and hold them unless they are already down.