Im wondering how to add flags that perfectly occupy the corner of maps, like the one below as an example.
Everything advised assuming you're using GIMP or a similar tool.
It looks like they had a large square image already that fit in the area - that you would either have to create yourself or modify from another file. So make a large image, rectangular, that fits in that area, roughly, where you want it, and put it on one layer. Then (if you're using GIMP, at least), you could go to your map layer and select the corner region. If it's a QBAM, then the corner is all one color, so just use the color select tool (Shift+O) or the Fuzzy Select Tool (U). You have to be careful here to make sure your threshold is low enough. This shouldn't be a problem with a QBAM map, but on other situations where you have similar colors, this is a problem. While using either of the tools, click and hold on the region you want to select and drag up. This will reduce the threshold (dragging down increases it). Or, in the tool options window, you can manually reduce the amount of Threshold. If you want a selection involving only the shade you are selecting, set the threshold to zero.
Note too that you can add to a selection by holding shift while using any selection tool.
Once the selection is made, there are two more steps. We currently have the outside border where the flag will go selected. Next, hit Ctrl+I or go into the selection menu to invert the selection - this is to select everything
but the region the flag is being put in. Now, here is the optional part: if you desire for there to be a one pixel border, as shown above, go into the selection panel and select Grow Selection, and increase it by 1 pixel. Alternatively, you could have done this before inverting the selection, which would require Shrinking the selection by one instead. But, now that you have your selection, return to the flag layer and select the eraser tool. Make it nice and large, and then erase everything in your selection, which are all parts of the flag that are not in the corner.