How to merge (boolean) two objects that share faces/edges
Boolean operation doesnt handle this co-planar faces, known issue. That is why I used in thelink Remesh. In your case (from screens) it can be done by several ways.


like in your last screen higher cylinder, after boolean select upper vertices, scale (S) Z = 0, than delete (X) Limited Disolve (or after boolean ad another cube and cut it from both sides at once)
on top of cylinder add rectangle in edit mode and use Knife Project so you got edges on place were cube cross cylinder, select faces and extrude
or try Remesh Modifier with some luck https://blender.stackexchange.com/a/165574/2214


... or any other technique, but there is no direct setup for Booleans to fix this issue, sorry.