As I recall (DX?) Brainiac 5 is descended from a line of robots that Bad!Brainiac created.
Almost. He is descended from Vril Dox, aka Brainiac 2, who in the original canon was Brainiac's forcibly adopted son. (The idea was that having a son would help conceal the fact that Brainiac was actually an android. Shrug.) Later, Vril lead the revolt that toppled the computers that built Brainiac and were controlling Vril's homeworld of Colu. Native Coluans all have genetically enhanced intelligence, and Brainiac had further enhanced Vril to twelfth level intelligence, which was really a dumb thing to do in retrospect if you're Brainiac. Then post-Crisis reset, Vril became the leader of L.E.G.I.O.N., but I don't know if they erased the original Brainiac conection.
Brainiac 5 is Querl Dox, Vril's great grandson, who inherited Vril's twelfth level intelligence.