しとく comes from しておく, which in turn comes from して置く. The literal translation of して置く would be, "do it, and then put [the results]". Basically it describes the act of doing something and storing the result of that so that when that result becomes useful, you can use it.
This literal meaning changed overtime (I presume) and しておく became to mean "do something to prepare for something that might happen". In case of
秘密にしておく, the speaker is saying that he/she will keep it secret in case it turns out whatever thing they were discussing indeed needed to be kept secret. I guess it makes some sense, as you could think that the state of that thing being kept secret, is "stored" or "put" somewhere, and then it turns out that that state was useful, or something like that.
The nuance further changed (I presume!), and it became ok to use it almost as a softner. For example, a Japanese speaker might say
今日飲んどく？ instead of
今日飲みに行く？. Technically it still means to drink "just in case", but here it's just used to soften the speech. 秘密にしておく could also be a softner, depending on the context.
-> Let's keep it secret for the time being, in case it it wise to keep it as a secret.
しておく is frequently used with とりあえず, which translates to "for the time being".
Both are ok, while the latter is colloquial.
Above is another example. しとく is more frank/colloquial form of しておく.
～おく can also work with other verbs. Here are some examples:
Apparently it's even more complex than that. Here is a Japanese paper on ～ておく's meaning.