It's a timing issue rather than a bug. You need to wait for a popup menu to actually appear before you can act upon it. So if you want all the keystrokes in one script (i.e. without using native KM actions), you can do this (no cliclick required):
Script
try
with timeout of 0.3 seconds
activate application "Logic Pro X"
tell application "System Events"
tell process "Logic Pro"
set tracks_window to title of first window whose title contains "- Tracks"
click menu button 2 of group 1 of group 1 of group 4 of window tracks_window
delay 0.1
keystroke "MIDI"
key code 124
keystroke "Humanize"
key code 36
end tell
end tell
end timeout
end try