How to replace Momentary & Maintained switch with Teensy?
Declaring pin modes should remain in the setup function, as it shouldn't change during the program.

Also, you can keep the button state in a variable and change it later as you simulate a push :

bool btnState = false;
// ...
setup(){
      pinMode(PIN_D5, OUTPUT);
      pinMode(PIN_D6, OUTPUT);
    }

void switchButton(){
  btnState = !btnState;
  digitalWrite(PIN_D6, btnState);
}


[EDIT]

If you want to simulate a momentary pushed button, you may need to wait a little while between pressing and releasing a given button as below :

void pressButton(int button){
  digitalWrite(button, HIGH);
  delay(100);
  digitalWrite(button, LOW);
}


NB : depending on your LCD driver board logic, you may need to change HIGH level to LOW and vice-versa