It's pretty clear to me that he did think about the election. That's the problem.
Uneven enforcement against black people is unfair and awful and should be fixed. Uneven enforcement against whichever party is not currently in power is a threat to democracy itself.
I disagree with your analysis. I think it's likely that Alvin Bragg is not a dumb guy. It is well known that a conviction would not prevent Trump from running for President. He also probably had a number of smart people giving him advice that this was going to do a lot to increase Trump's visibility and in general energize his base. If anything, the degree to which he considered it probably acted as a detractor, not the reason he went through with it.
I think Bragg prosecuted because of the reason that all prosecutors go after high profile cases in big regions. He knew it would bring him attention and he thought he had a good chance to win. In Alvin Bragg's world, that's enough to get you over the line.