a condition / function executes in a period without calling it.

working on a system like ATM machine.( password , username )
tft screen and keypad is used.
it is driven by number of keypress (i)
but if (buff[15] =='X') but when i didnt do any thing ( without any key press ) this line runs within some time constant.

code may look long but its easy to go through :relaxed:

    #define LCD_CS A3
    #define LCD_CD A2   
    #define LCD_WR A1   
    #define LCD_RD A0   

    #define LCD_RESET A4

    #define   BLACK           0x0000
    #define   BLUE            0x001F
    #define   RED             0xF800
    #define   GREEN           0x07E0
    #define   CYAN            0x07FF
    #define   MAGENTA         0xF81F
    #define   YELLOW          0xFFE0
    #define   WHITE           0xFFFF

    #include "TFTLCD.h"
    #include <Keypad.h>

    const byte ROWS = 5;
    const byte COLS = 4;
    char buff[15];
    long lastUpdate = 0;
    int x,i,e,k,xx;
    int j=11;

    TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

    char keys[ROWS][COLS] =
    {
      {'1','6','A','D'},
      {'2','7','B','E'},
      {'3','8','C','X'},
      {'4','9','Q','Y'},
      {'5','0','E','Z'},

    };

    byte rowPins[ROWS] = {40,39,38,37,36}; //connect to row pinouts
    byte colPins[COLS] = {32,33,34,35}; //connect to column pinouts

    Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

  
  
  
  
//-------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------
  
    void setup(void)
    {
      Serial.begin(9600);
      Serial.println("      User Interface Menu Started!        ");
      tft.reset();
      tft.initDisplay();
    }

void(* resetFunc) (void) = 0;

   
    void loop(void)
{
      
    
      char key = keypad.getKey();
      if (key  != NO_KEY)

    {
        buff[i] = key;
        i = i+1;
      
       x=x+4;
      } 
    
      if((millis() - lastUpdate) > 700)                                                      // has it been >1 second since the last update?
     {
       
      if(i<10)
      {
      testtext(BLACK); 
      lastUpdate = millis();     
      }
     
     
     if (buff[10] == 'Z' )                                                                        //  RESET  at 10 th press  ..................
   { 
     
      i=0;
      testtext8(BLACK) ;    
      resetFunc();      
   } 
 
  if (buff[10] =='X')
      {       
      testtext5(BLACK); 
      lastUpdate = millis();
      }
     }
     
    if ( i==10)                                                                              // ask user to retry or enter the number inputed
    { 
    testtext2(WHITE);
    }
     
   
    if (buff[10] =='Y')                                                                      // RETRY                 
      {
      i=0;
      testtext3(BLACK) ;    
      resetFunc();      
      }
      
     
      if (buff[10] =='X')                                                                     // STUDENT ID- ok   /    NOW >>>>>> PASSWORD    
    {   
      if(e<10)
      {
      Serial.print(buff[e]);
      e++;
      }
 
     }
     
     
      if ( i==15)                                                                               // ask Password correct ?????????????????
      { 
        testtext6(WHITE);
      }
     
     
      if (buff[15] =='X')                                                                         // if CORRECT !!!!!!        
    {
      
        testtext7(BLACK);    
        Serial.println();  
        Serial.print(buff[11]);
        Serial.print(buff[12]);
        Serial.print(buff[13]);
        Serial.print(buff[14]);
        Serial.print("#");                                                
    }
      
    
    if (buff[15] =='Y')                                                                              // if WRONG :(                                              
    
    { i=11;
     testtext5(BLACK);                                     
    } 
     
     
      if (buff[15] =='Z')                                                                              // RESET AT 16 th press                                           
    { 
      i=0;
      testtext8(BLACK) ;    
      resetFunc();                                       
    } 
     
     
     
   }
    
      
    
    
    //------------------------------------------------------------------------------------------------------------------------------------
    //-------------------------------------------------------------------------------------------------------------------------------------

    void testtext(uint16_t color)                                                                   // 10 press in the beginning
       
{
       if( i<11 )
     {
      tft.fillScreen(YELLOW);
      tft.setCursor(50, 20);
      tft.setTextColor(RED);
      tft.setTextSize(2);
      tft.println("EEEEEEE");
      tft.setCursor(50, 40);
      tft.setTextSize(2);
      tft.println("STUDENT ID");

      tft.setCursor(x, 75);
      tft.setTextSize(2);
      tft.print(buff);
     }
}
    

    void testtext2(uint16_t color)                                                               // asking is the number entered is right or wrong
    {
      //  Serial.println("-its 11th press-");
      tft.setCursor(60, 100);
      tft.setTextColor(GREEN);
      tft.setTextSize(2);
      tft.drawRect(tft.width() -60, tft.height() -80, 40 , 25, RED);
      tft.print(" if correct");
      tft.setCursor(60, 120);
      tft.print(" press  Enter");
      tft.setCursor(60, 180);
      tft.setTextColor(RED);
      tft.drawRect(tft.width() -60 , tft.height() -80, 40 , 30, RED); 
      tft.print("if wrong ");
      tft.setCursor(60, 200);
      tft.print("press  Cancel");
    }

    void testtext3(uint16_t color)                                                                         // if wrong
    {
      tft.drawRect(0, 0, tft.width(), tft.height(), WHITE);
      //tft.drawRect(tft.width() -0, tft.height() -0,240,320, CYAN);
      tft.fillRect(0, 0, tft.width(), tft.height(), WHITE);
      tft.setCursor(50, 80);
      tft.setTextColor(BLUE);
      tft.setTextSize(2);
      tft.print(" Enter Again ");
    }

    void testtext4(uint16_t color)                                                                           // if right ?
    {
      tft.fillScreen(CYAN);
      tft.setCursor(180, 190);
      tft.setTextColor(RED);
      tft.setTextSize(2);
      tft.print(" number is entered"); 
    }
    
   
   
    void testtext5(uint16_t color)                                                                            // PASSWORD INSERTING
  {  
    if(i>10 && i<16)
     {
      tft.fillScreen(BLACK);
      tft.setCursor(50, 50);
      tft.setTextColor(RED);
      tft.setTextSize(2);
      tft.println("ENTER");
      tft.setCursor(50, 70);
      tft.setTextSize(2);
      tft.println("PASSWORD");

      tft.setCursor(x, 105);
      tft.setTextSize(2);
      tft.print( buff[11]);
      tft.print( buff[12]);
      tft.print( buff[13]);
      tft.print( buff[14]);
     }
}


    void testtext6(uint16_t color)                                                                           // ask PASSWORD correct ???????
    {
      //  Serial.println("15 th press ");
      tft.setCursor(60, 160);
      tft.setTextColor(YELLOW);
      tft.setTextSize(2);
      tft.drawRect(tft.width() -60, tft.height() -80, 40 , 25, RED);
      tft.print(" CORRECT");
      tft.setCursor(60, 180);
      tft.print(" press  Enter");
      tft.setCursor(60, 200);
      tft.setTextColor(RED);
      tft.drawRect(tft.width() -60 , tft.height() -80, 40 , 30, RED); 
      tft.print("WRONG ");
      tft.setCursor(60, 220);
      tft.print("press  Cancel");
    }

 void testtext7(uint16_t color)                                                                              // NOW >>>>>> SERIAL >>>>>>>>>>>>>>>>>>>>>>>>>>>>
    {
      //  Serial.println("CONGURATUALTIONS NOW U CAN MOVE ON");
       tft.drawRect(0, 0, tft.width(), tft.height(), WHITE);
      //tft.drawRect(tft.width() -0, tft.height() -0,240,320, CYAN);
      tft.fillRect(0, 0, tft.width(), tft.height(), WHITE);
      tft.setCursor(50, 20);
      tft.setTextColor(RED);
      tft.setTextSize(2);
      tft.println("SERIAL COMMUNICATION ");
    }
    
    
     void testtext8(uint16_t color)                                                                             //  RESET
    {
      
     Serial.print(" RESET OK ");
      tft.drawRect(0, 0, tft.width(), tft.height(), WHITE);
      //tft.drawRect(tft.width() -0, tft.height() -0,240,320, CYAN);
      tft.fillRect(0, 0, tft.width(), tft.height(), WHITE);
      tft.setCursor(50, 80);
      tft.setTextColor(BLUE);
      tft.setTextSize(2);
      //tft.print();     
    }

Please modify your post, (upper right of your post)

select all the code (without the tags), copy it into the IDE , press CTRL T, (optional save), copy it back between the code tags, and save it again.

this will reformat the layout making the code more readable (and thus debugable)

Where does buff[15] get reset to something besides 'X', 'Y', or 'Z' once that value gets put in there?
I think you need to clear it out after you act on it.