I was a bit confused by the output of a bwa read-alignment. I have observations that return a good CIGAR value but poor MAPQ value. This alignment was obtained from converting a BAM file -> BED file that was generated with bwa mem.

    chr1    142536052       142536087       336_1362_95     0       -       16      35M     *       0       0       CACTCCAGACTCGGTGACAGAGTGAGATCCTGTCG  8?@?.:/@@@@@@@@@@@@@@@>?@@@@?@@>@=@     NM:i:1  MD:Z:8T26       AS:i:30 XS:i:29

I thought CIGAR values and MAPQ value should be correlated but this breaks my intuition. Any insights would be super helpful. Thanks!
The cigar string tells you how well the alignment matches the reference. That doesn't mean the nucleotide match, but that's not the point here.

The mapping quality tells you how likely this location is indeed the correct location for this read. A read matching perfectly to a repetitive element will have a low mapping quality because you are unsure about its exact location, it's a multi-mapping read.