Here is an analogy to explain how someone can be both just and merciful.
You get pulled over by a police officer, you were going 15 miles/hour above the speed limit. If the police officer lets you go free of anything he would be merciful but not just. If the police officer arrests you and puts you in jail for 3 months, he would be just and not merciful. So how does he become both just and merciful? Here are some ways:
1.) Let you go with a warning and put it on your record (if in the future you commit the crime again, the punishment will be more severe)
2.) Charge less on your speeding ticket price.
Let's say you ask for forgiveness to the police officer and he let's you off with a warning. Here the police officer was merciful and just. But if you go on and speed again, the police officer was already merciful, but now you will get a more severe punishment. That is exactly how it works with Allah. You ask for forgiveness--okay it is forgiven with the condition you would not do the sin again. If you do the sin again, Allah was already merciful to you, now you won't be forgiven again.
Or let's say the police gives you a lower speeding ticket price. That way justice was served and mercy was displayed.
Justice and Mercy goes hand in hand.
"Your Allah randomly chooses to forgive or not forgive. How can a Muslim know when Allah has forgiven you? In other words, I am asking how does Allah demonstrate (show you) his justice and mercy. Remember, the attributes of God cannot conflict. His justice and mercy must be equal at all times. How does Allah do that?"
"When you say Allah was merciful to you and forgave you, how does that equal justice requiring that a penalty be paid?"
First of all, Allah does not randomly choose to forgive or not. You don't know if Allah has forgiven you, you just hope he did and you repent. There is no magic "poof" that means you are forgiven, it is completely up to Allah.
For the second question, you assume that Allah would be merciful at the expense of justice. As I have shown, both justice and mercy can be observed simultaneously and they are not logical contradictions.
It is not impossible to be both just and merciful.
----