arduino based security lock

First of all, I think you can clean the code up a lot, but you have probably gathered that from the comments above. To do what you want depends on the capability of the GSM shield. I assume it can receive messages? You need to understand how to interrogate it to see if messages are waiting to be processed, and how to get the message from the shield into your program. Then you can work on the program code:

Pseudo code:

setup()
{
    Initialise inputs and outputs
    enable keypad
    initialise GSM module
}


loop()
{
    check for GSM message
    if GSM message is available {
        if GSM message is to lock keypad {
            disable keypad
        } else if GSM message is to unlock keypad {
            enable keypad
        }
    }

    if keypad is enabled {
        process key
    }
}

I haven't made any attempt to untangle the input processing and the handling of the wrong entries - I leave that for you.