To-hit roll is rolled as x dice with y sides each.
x is dex/4 + melee/2 + weapon’s to-hit + weapon skill bonus.
Weapon skill bonus is unarmed/2 (if unarmed) or best applicable skill/3, where weapon needs at least 8 damage of relevant type to get bonus from a given skill.
Dex is rounded down, melee and weapon skill bonus are added up and then rounded down.
x has a low cap of 1.
y is 10 - encumbrance/10, but no less than 2.
If encumbrance isn’t divisible by 10, the remainder is rolled (say, 54 encumbrance has 60% chance to count as 50 and 40% chance to count as 60).
Weapons getting stuck depends on weapon’s “cutting type” (chop, slice, pierce, spear), bashing/(cut+stab) ratio, your weapon skill (cut/stab), your strength and your current attack speed with the weapon (tired = stuck).
Machetes are terrible at not getting stuck (but have nice stats otherwise) and you need 5 cutting skill and high stamina to be safe from sticking when using them.
Fire axes are a bit safer (more bashing), then wood axes, knives (knives have good attacks speeds), spears and swords.
Slicing weapons like katanas are very unlikely to get stuck.
This stamina sticking may be a bug. It can pull out very un-sticky weapons easily.