As explained in the documentation Using InputEvent — Godot Engine (stable) documentation in English the physics picking event (what you are using for the enemy) is the last step in the input event chain so whatever step you are using for checking if the map has been clicked will probably come first.
The easiest fix I can think of is to use a Control node in your enemy to intercept the mouse events by connecting its Control.gui_input signal to the function and Viewport.set_input_as_handled() the event when needed
How are you dealing with the tilemap input event? Are you using _input() or _unhandled_input(). If you are using _input() then change it to _unhandled_input() so it happens after _gui_input() as the documentation I linked above explains.
This work fine:
extends Node
@onready var sprite_2d: Sprite2D = $CharacterBody2D/Sprite2D
@onready var tile_map_layer: TileMapLayer = $TileMapLayer
func _ready() -> void:
$CharacterBody2D/Control.gui_input.connect(func(event):
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
sprite_2d.modulate = Color.RED
tile_map_layer.modulate = Color.WHITE
get_viewport().set_input_as_handled()
)
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
sprite_2d.modulate = Color.WHITE
tile_map_layer.modulate = Color.RED