There are a couple of different ways, but you probably would need a custom cap made up:
1 - You can mount the cap to the brick from the side as in the first picture:
2 - You can mount the cap to the top of the chimney:
Pictures from: https://www.riversidesheetmetal.net/chimney-caps/
To mount from the side of the chimney, people normally use anchors, such as these or these. You need to drill the side of the cap or get it made pre drilled for this.
You can also glue it down if you want, either mounted from the top (more common) or side.
A lot of people like to use something called liquid nails for that (top mount). If it was me I'd probably do both (depending on how much you actually pay for a cap, its not a bad idea) just to be sure, but if not, then I would anchor it from the side. Liquid nails is quicker, just make sure you get something appropriate.