To dig a moat in Stronghold Crusader, start by going to the Castle Buildings tab. From there, head to the gates section where you'll see all the different gates available to build.
On the right side of that tab, you'll spot two spades; click the one at the bottom to build a moat. Then order your archers, engineers, or spearmen to dig it out. With those steps, you'll have your moat in place.