This study explores the impact of the magnetic field on heat transfer and entropy generation in a simulated electronic device using magnetohydrodynamic principles through a three-dimensional hybrid Runge–Kutta and lattice Boltzmann method. By varying Rayleigh number (Ra) from 103 to 106 and Hartmann number (Ha) between 0 and 100, the research evaluated the influence of these parameters on the average Nusselt number (⟨Nu⟩), heat exchange ratio (R), and entropy generation within a confined cavity. The results demonstrated that higher Ra values, particularly for Ra ≥105, significantly enhance convective heat transfer, as reflected by an increase in ⟨Nu⟩. However, introducing a magnetic field (Ha = 50, 100) diminishes this effect by damping fluid motion, resulting in a reduction of ⟨Nu⟩. The heat exchange ratio increases with Ra, reaching a peak value of 0.93 for Ha = 100 and Ra = 105, indicating improved heat dissipation under the magnetic influence. In terms of entropy generation, at low Ra (Ra = 103), thermal conduction is the predominant heat transfer mechanism, with entropy primarily generated due to thermal effects. As Ra increases to 106, the system shifted toward a convection-dominated regime, where entropy generated by viscous effects becomes more significant. Under stronger magnetic fields, particularly at Ha = 100, magnetic entropy generation emerges as a dominant factor, further increasing energy dissipation. These results suggested that magnetic fields can be strategically applied to optimize thermal management in electronic devices by controlling both heat transfer and entropy generation. The effectiveness of this approach, however, is highly dependent on the specific flow conditions and the strength of the applied magnetic field.